2015 Multi-University Training Contest 2 Friends
Friends
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
For each testcase, the first line contains two integers n (1≤n≤8) and m (0≤m≤n(n−1)2), indicating the number of people and the number of pairs of friends, respectively. Each of the next m lines contains two numbers x and y, which mean x and y are friends. It is guaranteed that x≠y and every friend relationship will appear at most once.
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn = ;
struct arc {
int u,v;
} e[maxn];
int st[maxn],du[maxn],n,m,ret;
bool check() {
for(int i = ; i <= n; ++i)
if(st[i]) return false;
return true;
}
bool check2(int x){
if(st[x] == && (du[x]&) == ) return true;
int tmp = st[x]<?du[x]+st[x]:du[x]-st[x];
if(st[x] < && tmp >= && (tmp&) == ) return true;
if(st[x] > && tmp >= && (tmp&) == ) return true;
return false;
}
void dfs(int cur) {
if(cur == m) {
if(check()) ++ret;
return;
}
++st[e[cur].u];
++st[e[cur].v];
--du[e[cur].u];
--du[e[cur].v];
if(check2(e[cur].u) && check2(e[cur].v)) dfs(cur+);
st[e[cur].v] -= ;
st[e[cur].u] -= ;
if(check2(e[cur].u && check2(e[cur].v))) dfs(cur+);
++st[e[cur].v];
++st[e[cur].u];
++du[e[cur].u];
++du[e[cur].v];
}
int main() {
int kase;
scanf("%d",&kase);
while(kase--) {
scanf("%d%d",&n,&m);
memset(du,,sizeof du);
memset(st,,sizeof st);
for(int i = ret = ; i < m; ++i) {
scanf("%d%d",&e[i].u,&e[i].v);
++du[e[i].u];
++du[e[i].v];
}
bool flag = true;
for(int i = ; i <= n && flag; ++i)
if(du[i]&) flag = false;
if(flag) dfs();
printf("%d\n",ret);
}
return ;
}
2015 Multi-University Training Contest 2 Friends的更多相关文章
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 UESTC Winter Training #8【The 2011 Rocky Mountain Regional Contest】
2015 UESTC Winter Training #8 The 2011 Rocky Mountain Regional Contest Regionals 2011 >> North ...
- 2015 UESTC Winter Training #7【2010-2011 Petrozavodsk Winter Training Camp, Saratov State U Contest】
2015 UESTC Winter Training #7 2010-2011 Petrozavodsk Winter Training Camp, Saratov State U Contest 据 ...
- Root(hdu5777+扩展欧几里得+原根)2015 Multi-University Training Contest 7
Root Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Su ...
- 2015 Multi-University Training Contest 6 solutions BY ZJU(部分解题报告)
官方解题报告:http://bestcoder.hdu.edu.cn/blog/2015-multi-university-training-contest-6-solutions-by-zju/ 表 ...
- HDU 5360 Hiking(优先队列)2015 Multi-University Training Contest 6
Hiking Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total S ...
- hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)
OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- HDU5294 Tricks Device(最大流+SPFA) 2015 Multi-University Training Contest 1
Tricks Device Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- hdu 5416 CRB and Tree(2015 Multi-University Training Contest 10)
CRB and Tree Time Limit: 8000/4000 MS (J ...
- 2015多校联合训练赛 hdu 5308 I Wanna Become A 24-Point Master 2015 Multi-University Training Contest 2 构造题
I Wanna Become A 24-Point Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 ...
随机推荐
- zabbbix4.0升级到4.2
一.添加Zabbix存储库 1.安装存储库配置包. rpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4 ...
- java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap
最近在使用java PiO导入导出Excle在windos本机上运行没有问题: 但是!!问题来了!放到Linux服务器上部署后出现异常 java.lang.NoClassDefFoundError: ...
- 如何成为资深的python专家
相信很多人有这种感受,python很简单,几天就学会了:做了一段时间就觉得python没什么好玩的,就这样. 一种语言有火这么久,必有它存在的道理. 第一.我们要相信她,她就像你的新女朋友一样,她会给 ...
- 小学生都能学会的python(字典{ })
小学生都能学会的python(字典{ }) 1. 什么是字典 dict. 以{}表示. 每一项用逗号隔开, 内部元素用key:value的形式来保存数据 {"jj":"林 ...
- 大道至简第一章读后感 Java伪代码形式
观看了大道至简的第一章之后,从愚公移山的故事中我们可以抽象出一个项目, 下面用Java 伪代码的形式来进行编写: import java(愚公移山的故事) //愚公移山 public class yu ...
- java源码之List(ArrayList,LinkList,Vertor)
1,List概括 List的框架图 (01) List 是一个接口,它继承于Collection的接口.它代表着有序的队列. (02) AbstractList 是一个抽象类,它继承于Abstract ...
- nginx配置修改
改变nginx配置想让它生效而不停止服务,如下两种方式都可以:1) 检查nginx配置: nginx -t; 配置重载: nginx -s reload2) 检查nginx配置: nginx -t; ...
- HDU 2686 Matrix(最大费用最大流+拆点)
题目链接:pid=2686">http://acm.hdu.edu.cn/showproblem.php?pid=2686 和POJ3422一样 删掉K把汇点与源点的容量改为2(由于有 ...
- 《Objective-C高级编程:iOS与OS X多线程和内存管理》读后感
拿到这本书的第一感觉是非常薄,可是内容就如同序里面所说,这不是一本面向刚開始学习的人的书,比較有深度,对C/C++全然不熟悉的话非常多东西会看不明确. 尽管此书在技术点上仅仅谈到了ARC.Blocks ...
- HDU 1392 凸包子
Surround the Trees Problem Description There are a lot of trees in an area. A peasant wants to buy a ...