博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 5952 连通子图
阅读量:6933 次
发布时间:2019-06-27

本文共 2163 字,大约阅读时间需要 7 分钟。

Counting Cliques

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

Total Submission(s): 184    Accepted Submission(s): 56

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

 

思路:构造一个团,如果一个点与这个团的所有点都有边,则将其加入团中,统计含s个点的团的个数。关于优化,可以建单向边来减少搜索量。

 

代码:

1 #include
2 //#include
3 #define db double 4 #include
5 #define ll long long 6 #define vec vector
7 #define Mt vector
8 #define ci(x) scanf("%d",&x) 9 #define cd(x) scanf("%lf",&x)10 #define cl(x) scanf("%lld",&x)11 #define pi(x) printf("%d\n",x)12 #define pd(x) printf("%f\n",x)13 #define pl(x) printf("%lld\n",x)14 #define MP make_pair15 #define PB push_back16 #define inf 0x3f3f3f3f3f3f3f3f17 #define fr(i,a,b) for(int i=a;i<=b;i++)18 const int N=1e3+5;19 const int mod=1e9+7;20 const int MOD=mod-1;21 const db eps=1e-18;22 using namespace std;23 bool d[105][105];24 int n,m,s,t;25 int ans;26 vector
g[N];27 void dfs(int u,int *a,int cnt)28 {29 if(cnt==s){30 ans++;31 return;32 }33 bool ok;34 for(int i=0;i
v) swap(u,v);63 g[u].push_back(v);64 d[u][v]=d[v][u]=1;65 }66 for(int i=1;i<=n;i++){67 if(g[i].size()>=s-1){68 int a[105];69 a[1]=i;//构建团70 int cnt=1;71 dfs(i,a,cnt);72 }73 }74 pi(ans);75 }76 return 0;77 }

 

转载于:https://www.cnblogs.com/mj-liylho/p/7624924.html

你可能感兴趣的文章
perl连接mysql的例子
查看>>
windows server 2008虚拟化技术一览
查看>>
webpack2 实践
查看>>
Linux系统日志介绍分析
查看>>
Linux下Tomcat的启动、关闭、杀死进程
查看>>
FTP服务器的防火墙通用设置规则
查看>>
简单记事本及目录树形图的Java实现
查看>>
android 在使用ViewAnimationUtils.createCircularReveal()无法兼容低版本的情况下,另行实现圆形scale动画...
查看>>
Application Virtualization 4.5 部署之(一)
查看>>
获取ip地址解析归属地
查看>>
启用日志调试Kerberos登录验证问题
查看>>
saltstack二次开发构建自己的api
查看>>
动手打造自己强大的右键菜单
查看>>
探测调试器
查看>>
图案研究2--九格定义
查看>>
通过串口关闭Linux服务器
查看>>
RHEL 5服务篇—使用Apache搭建web服务(四)部署AWStats网站分析系统
查看>>
SQL Serer闩锁 和 闩锁超时故障排除
查看>>
Logparser 分析 Exchange 日志文件
查看>>
KDE与GNOME的起源与发展
查看>>