HDU 5952 Counting Cliques(无向图定向搜索)
来源:互联网 发布:淘宝售假次数如何计算 编辑:程序博客网 时间:2024/06/11 14:48
Counting Cliques
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3480 Accepted Submission(s): 1254
Problem Description
A clique is a complete graph, in which there is an edge between every pair of the vertices. Given a graph with N vertices and M edges, your task is to count the number of cliques with a specific size S in the graph.
Input
The first line is the number of test cases. For each test case, the first line contains 3 integers N,M and S (N ≤ 100,M ≤ 1000,2 ≤ S ≤ 10), each of the following M lines contains 2 integers u and v (1 ≤ u < v ≤ N), which means there is an edge between vertices u and v. It is guaranteed that the maximum degree of the vertices is no larger than 20.
Output
For each test case, output the number of cliques with size S in the graph.
Sample Input
3
4 3 2
1 2
2 3
3 4
5 9 3
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
6 15 4
1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6
4 5
4 6
5 6
Sample Output
3
7
15
Source
2016ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)
Recommend
jiangzijing2015
题目大意
有一张最多
解题思路
最大团极大团问题是NP问题,所以这题也很自然地想到搜索。不过如果直接暴搜的话可以发现对于每个大小为
AC代码
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>#include<vector>#include<queue>#include<stack>#include<map>#include<set>using namespace std;#define LL long long#define INF 0x3f3f3f3fconst int MAXV=100+3;int V, E, S;vector<int> G[MAXV];bool maze[MAXV][MAXV];int ans;int save[MAXV];void init(){ for(int i=0;i<=V;++i) G[i].clear(); for(int i=0;i<=V;++i) for(int j=0;j<=V;++j) maze[i][j]=false; ans=0;}void dfs(int u, int n){ if(n==S) { ++ans; return ; } for(int i=0;i<G[u].size();++i) { int v=G[u][i]; bool ok=true; for(int j=0;j<n;++j) if(!maze[save[j]][v]) { ok=false; break; } if(!ok) continue; save[n]=v; dfs(v, n+1); }}int main(){ int T_T; scanf("%d", &T_T); while(T_T--) { scanf("%d%d%d", &V, &E, &S); init(); for(int i=0;i<E;++i) { int u, v; scanf("%d%d", &u, &v); if(u<=v) { G[u].push_back(v); maze[u][v]=true; } else { G[v].push_back(u); maze[v][u]=true; } } for(int u=0;u<V;++u) if(G[u].size()+1>=S) { save[0]=u; dfs(u, 1); } printf("%d\n", ans); } return 0;}
- HDU 5952 Counting Cliques(无向图定向搜索)
- HDU-5952-Counting Cliques(搜索剪枝)
- HDU 5952 Counting Cliques 暴力搜索
- -----暴力搜索-hdu 5952 Counting Cliques
- HDU 5952 - Counting Cliques
- hdu 5952 Counting Cliques
- hdu 5952 Counting Cliques
- hdu 5952 Counting Cliques
- HDU 5952 Counting Cliques 图DFS
- hdu 5952Counting Cliques(dfs优化)
- hdu5952 Counting Cliques(搜索)
- 【HDU 5952】Counting Cliques 【最大团思想+搜索】
- hdu 5952 Counting Cliques 暴力搜索 2016沈阳区域赛
- ICPC沈阳站E题 HDU 5952 Counting Cliques 搜索
- HDU 5952 Counting Cliques 暴力搜索+巧妙建边
- [hdu 5952 Counting Cliques]暴搜
- hdu 5952Counting Cliques(暴搜)
- HDU 5952 Counting Cliques(dfs)
- 输出一个整数的每一位
- typedef
- 一张图看尽 Linux 内核运行原理
- 认识kettle
- 敏捷开发介绍
- HDU 5952 Counting Cliques(无向图定向搜索)
- C和指针之字符串编程练习6
- 1305 Immediate Decodability(字典树)
- 自定义类型(结构体、位段、枚举和联合)
- Statement、 PreparedStatement 、CallableStatement 区别和联系
- 在 Linux 下使用 find 指令查詢目錄與檔案的速查筆記
- jQuery
- 【hdu 4970】 Killing Monsters 【2014 Multi-University Training Contest 9 】
- Log4j2入门(1)-控制台日志输出