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. 

InputThe 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.OutputFor 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 思路:
如何找到一个k阶的完全图?如果一个图是完全图,那么引入一个新的点,这个点与原图中的每一点都有边相连,新图还是完全图。用了num数组来记录原图上的点。建图时,、只建了从编号小的点到编号大的点之间的边。
这是由于,每次没有必要建立反向边。反而不建反向边的话,会少了去重的过程。
代码:
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
vector<int>u[maxn];
int n,m,k;
int ans;
int top;
int num[maxn];
bool mp[maxn][maxn];
void dfs(int t,int d)
{
if(d==k){ans++;return;}
int siz = u[t].size();
bool flag = false;
for(int i=;i<siz;i++){
int cnt = u[t][i];
flag = false;
for(int j=;j<=top;j++){
if(!mp[cnt][num[j]]){flag = true;break;}
}
if(flag){continue;} num[++top]=cnt;
dfs(cnt,d+);
top--;
}
} int main()
{
int T;
scanf("%d",&T);
while(T--){
ans = ;
scanf("%d%d%d",&n,&m,&k);
memset(mp,,sizeof(mp));
for(int i=;i<=n;i++){
u[i].clear();
}
int x,y;
for(int i=;i<=m;i++){
scanf("%d%d",&x,&y);
if(x>y){swap(x,y);}
u[x].push_back(y);
mp[x][y]=mp[y][x]=true;
} for(int i=;i<=n;i++){
num[++top]=i;
dfs(i,);
top--;
}
printf("%d\n",ans);
}
return ;
}
 

HDU - 5952 Counting Cliques(DFS)的更多相关文章

  1. HDU - 5952 Counting Cliques(dfs搜索)

    题目: A clique is a complete graph, in which there is an edge between every pair of the vertices. Give ...

  2. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  3. HDU 5952 Counting Cliques(dfs)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  4. HDU - 5952 Counting Cliques

    Counting Cliques HDU - 5952 OJ-ID: hdu-5952 author:Caution_X date of submission:20191110 tags:dfs,gr ...

  5. hdu 5952 Counting Cliques 求图中指定大小的团的个数 暴搜

    题目链接 题意 给定一个\(n个点,m条边\)的无向图,找出其中大小为\(s\)的完全图个数\((n\leq 100,m\leq 1000,s\leq 10)\). 思路 暴搜. 搜索的时候判断要加进 ...

  6. Counting Cliques HDU - 5952 单向边dfs

    题目:题目链接 思路:这道题vj上Time limit:4000 ms,HDU上Time Limit: 8000/4000 MS (Java/Others),且不考虑oj测评机比现场赛慢很多,但10月 ...

  7. hdu 3887 Counting Offspring dfs序+树状数组

    Counting Offspring Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  8. HDU 2952 Counting Sheep(DFS)

    题目链接 Problem Description A while ago I had trouble sleeping. I used to lie awake, staring at the cei ...

  9. HDU5952 Counting Cliques计算完全图的个数 巧妙构图+dfs

    题目传送门 题目大意:给出n个点,m条无向边,让你计算这幅母图中有几个大小为s的完全图. 完全图的意思是任意一个点都和其他点直接相连,完全图的大小指的就是完全图点的个数. 思路:比较巧妙的构图方式.我 ...

随机推荐

  1. crontab 从nano 转换为 vim

      crontab默认编辑器为nano,不方便使用. 修改crontab默认编辑器为vi或者其他的编辑器. export EDITOR="/usr/bin/vim" ; cront ...

  2. Mysql 查看连接数,状态 最大并发数(赞)

    Mysql 查看连接数,状态 最大并发数(赞)   -- show variables like '%max_connections%'; 查看最大连接数 set global max_connect ...

  3. git 强制推送

    Git 强制推送方法(一般不建议使用) $ git push -u origin master -f

  4. 【hihocoder 1628】K-Dimensional Foil(线性代数)

    hihocoder 1627 The 2017 ACM-ICPC Asia Beijing Regional Contest 北京区域赛 B.K-Dimensional Foil 题意 给定N个点的前 ...

  5. 正睿 2019 省选附加赛 Day10

    A 核心就是一个公式 \[\sum_{i = 0}^{k} S(k, i) \tbinom{x}{i} i\] S是第二类斯特林数 递推公式 \(S_2(n,k)=S_2(n−1,k−1)+kS_2( ...

  6. 三天STL与pbds(平板电视)

    19.02.11 ~ 19.02.13 hjmmm要专攻STL辣 先列一下大纲? 第一天:各种基础容器 第二天:实现平衡树和平板电视pbds 第三天:非变异算法和变异算法 那么我们就开始吧! Day1 ...

  7. 安装 linux-dash

    先看看软件的效果图,再介绍安装方法. 通过上图可以看到.软件可以实时监控CPU.内存.网络流量等相关信息,甚至可以监控到硬件信息安装方法:yum -y install httpd php zip un ...

  8. 【题解】 bzoj2982: combination (Lucas定理)

    题面戳我 Solution 板子题 Code //It is coded by ning_mew on 7.25 #include<bits/stdc++.h> #define LL lo ...

  9. 用c#查询各快递物流信息

    前面介绍过<用快递100接口查询各快递物流信息>,里面用的是API接口,但有些快递不支持这种方式,本文介绍的HtmlAPI支持所有快递公司. 支持包括EMS.邮政.顺丰和申通在内的所有公司 ...

  10. jquery扩展写法

    如何制作自己的Jquery插件,内容参考学习了网上的讲解,如下 使用这两个方法 jQuery.fn.extend(object) jQuery.extend(object) jQuery.extend ...