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 ...
随机推荐
- STM32 RTC
目前较为实用的RTC时钟源选择的是:32.768k LSE 低速外部时钟: 不建议实用LSI,精度不高,对时间精度要求不高的可以考虑实用LSI时钟源.数据手册上电气特性的数据:
- Yarn 工作机制
1.工作机制详述 (1)MR程序提交到客户端所在的节点. (2)YarnRunner向ResourceManager申请一个Application. (3)RM将该应用程序的资源路径返回给YarnRu ...
- CSS浏览器兼容性
答题技巧:因为这个问题主要是看你经验,一般有了开发经验的都会遇到这样的坑,你只要说出几个来大致就可以了. 1.对齐文本和文本输入框 问题: 当input元素在设置了高时,在IE7.IE8.IE9下会出 ...
- Redis基础都不会,好意思出去面试?
作者:张君鸿 juejin.im/post/5d078cd6f265da1b8466e62c Redis的数据结构 Redis支持多种不同的数据结构,包括5种基础数据结构和几种比较复杂的数据,这些数据 ...
- Java学习day6数组
---恢复内容开始--- Java数组 Java 语言中提供的数组是用来存储固定大小的同类型元素.你可以声明一个数组变量,如 numbers[100] 来代替直接声明 100 个独立变量 number ...
- 《剑指offer》面试题15 链表中的倒数第k个节点 Java版
书中方法:用两个节点一次遍历求得倒数第k个节点.注意头节点为空,k<=0,k大于节点个数的情况. public ListNode find(ListNode head, int k){ if(h ...
- Eureka注册中心高可用及常用配置项
一.前言 前面已经简单的介绍了 Eureka 注册中心的使用以及查看.下面将继续进行 Eureka 的说明以及应用. 二.Eureka 的高可用搭建 在实际生产项目中,为了保证服务的可用性,连续性,一 ...
- Ftp客户端(上传文件)
#coding=utf-8 import os import socket import hashlib import json # client = socket.socket() #申明socke ...
- vue css中scoped
1.什么是scoped vue组件中,在style标签中有一个属性,叫做scoped.当此标签拥有scoped属性的时候,该组件下的css样式只适用于本组件,而不会影响全局组件.这其实也相当于样式的模 ...
- HTML替换元素,非替换元素和控制元素
替换元素:元素内容由标签的属性来设置,标签其实就是一个占位符.替换元素因为元素内容来自外部资源,所以这些标签大多具有src,指明要引入的资源路径,所以大多仅需要一个标签就可以.例如:<link ...