HDU 5952 Counting Cliques(dfs)
Counting Cliques
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1855 Accepted Submission(s): 735
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
7
15
题意:
给你n个点,m条边,要你在这些点里面找大小为s 的完全图(完全图是指这个图里任意两点都有一条边)。
因为 N 只有100个。S最大也才10。所以我们可以爆搜来解决。然后我就T了 :(
因为 1 2 3 如果是完全图的话,那么 2 1 3 也是。所以我们多搜了很多次。
如果我们建边的时候是按照 小的指向 大的点来建,就可以避免了很多情况。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
using namespace std;
typedef long long LL;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
const LL INF = 0x7fffffff;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+;
const int maxn = +;
bool edge[maxn][maxn];
vector <int> E[maxn];
int num[maxn];
int p[];
int ans, n, m, s, u, v;
void init() {
ms(edge, );
ms(num, );
for(int i = ;i<maxn;i++) E[i].clear();
ans = ;
}
void dfs(int x, int len){
int flag = ;
for(int i=;i<len;i++){
if(!edge[x][p[i]]){
flag = ;
break;
}
}
if(!flag){
return;
}
p[len] = x;
if(len+==s){
ans++;
return;
}
for(int i = ;i<E[x].size();i++){
dfs(E[x][i], len+);
}
}
void solve() {
scanf("%d%d%d", &n, &m, &s);
for(int i = ;i<m;i++){
scanf("%d%d", &u, &v);
E[min(u, v)].pb(max(u, v));//小的点指向大的点
edge[u][v] = edge[v][u] = ;
num[u]++;
num[v]++;
}
for(int i = ;i<=n;i++){
if(num[i]<s-) continue;
dfs(i, );
}
printf("%d\n", ans);
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int T;
scanf("%d", &T);
while(T--){
init();
solve();
}
return ;
}
HDU 5952 Counting Cliques(dfs)的更多相关文章
- HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)
Counting Cliques Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU - 5952 Counting Cliques(dfs搜索)
题目: A clique is a complete graph, in which there is an edge between every pair of the vertices. Give ...
- HDU - 5952 Counting Cliques
Counting Cliques HDU - 5952 OJ-ID: hdu-5952 author:Caution_X date of submission:20191110 tags:dfs,gr ...
- 2017ACM暑期多校联合训练 - Team 1 1003 HDU 6035 Colorful Tree (dfs)
题目链接 Problem Description There is a tree with n nodes, each of which has a type of color represented ...
- hdu 1716 排序2(dfs)
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- [HDOJ5952]Counting Cliques(DFS,剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5952 题意:求图中规模为s的团的个数. DFS+剪枝,姿势不好很容易TLE啊. #include &l ...
- hdu 3887 Counting Offspring(DFS序【非递归】+树状数组)
题意: N个点形成一棵树.给出根结点P还有树结构的信息. 输出每个点的F[i].F[i]:以i为根的所有子结点中编号比i小的数的个数. 0<n<=10^5 思路: 方法一:直接DFS,进入 ...
- HDU - 5952 Counting Cliques(DFS)
A clique is a complete graph, in which there is an edge between every pair of the vertices. Given a ...
- HDU 3887 Counting Offspring(DFS序+树状数组)
Counting Offspring Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
随机推荐
- 【FICO系列】SAP 关于SAP中的记账码的解释
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[FICO系列]SAP 关于SAP中的记账码的解 ...
- 【ABAP系列】SAP WEB GUI的实现,SAP在网页中使用
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP WEB GUI的实现,SAP ...
- Django报错[WinError 123] 文件名、目录名或卷标语法不正确。: '<frozen importlib._bootstrap
当你在项目文件中删除app对应的文件 却没有在项目url中删除之前配置的路径 也没有删除setting中配置的app 那么就会报错[WinError 123] 文件名.目录名或卷标语法不正确.: '& ...
- web 前端1 拾遗
1.整体布局 三个div header body footer 2.div的居中 width:980px margin:0 auto 3.内联标签 inline #内联 无法使用高度.宽度 block ...
- linux内核的gpiolib详解
#include <linux/init.h> // __init __exit #include <linux/module.h> // module_init module ...
- BZOJ4753: [Jsoi2016]最佳团体(分数规划+树上背包)
BZOJ4753: [Jsoi2016]最佳团体(分数规划+树上背包) 标签:题解 阅读体验 BZOJ题目链接 洛谷题目链接 具体实现 看到分数和最值,考虑分数规划 我们要求的是一个\(\dfrac{ ...
- css中的居中的方法
一.垂直居中 (1)inline或者inline-*元素 1. 单行文字 设置上下padding相等 以前一直以为inline元素是没有上下的padding和margin的,其实不然,他们是有上下的p ...
- 模板 - 可持久化无旋Treap
空间消耗非常玄学,有多大开多大就完事了.其实是因为单次操作可能会有数次Merge和Split操作,按照下面的版本的话Merge和Split都进行复制,所以一次操作可能复制了4个版本. 四个函数式查询, ...
- GooglePlay
如何下载googlePLay的apk文件? 1.首先要知道apk的package名: 打开GooglePlay的页面,在地址栏里就会有https://play.google.com/store/app ...
- 《Cascaded Pyramid Network for Multi-Person Pose Estimation》论文阅读及复现笔记
一.PipeLine 要点 TopDown + GlobalNet + RefineNet 二.Motivation 通过提高对难以识别的关键点的识别准确率,来提升总体识别准确率. 方法:1.refi ...