Friends

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

Problem Description
There are n people and m pairs of friends. For every pair of friends, they can choose to become online friends (communicating using online applications) or offline friends (mostly using face-to-face communication). However, everyone in these n people wants to have the same number of online and offline friends (i.e. If one person has x onine friends, he or she must have x offline friends too, but different people can have different number of online or offline friends). Please determine how many ways there are to satisfy their requirements.
 
Input
The first line of the input is a single integer T (T=100), indicating the number of testcases.

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.

 
Output
For each testcase, print one number indicating the answer.
 
Sample Input
2
3 3
1 2
2 3
3 1
4 4
1 2
2 3
3 4
4 1
 
Sample Output
0
2
 
解题:直接枚举边很草啊。。。貌似别人都是枚举点,每个点的最后一条边可以推算出来。。。而哥直接艹了。。。
 
 #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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 据 ...

  4. 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 ...

  5. 2015 Multi-University Training Contest 6 solutions BY ZJU(部分解题报告)

    官方解题报告:http://bestcoder.hdu.edu.cn/blog/2015-multi-university-training-contest-6-solutions-by-zju/ 表 ...

  6. 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 ...

  7. hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)

    OO's Sequence                                                          Time Limit: 4000/2000 MS (Jav ...

  8. 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 ...

  9. hdu 5416 CRB and Tree(2015 Multi-University Training Contest 10)

    CRB and Tree                                                             Time Limit: 8000/4000 MS (J ...

  10. 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 ...

随机推荐

  1. 【XSY2692】杨柳 - 网络流

    题目来源:2018冬令营模拟测试赛(十) 题解: 继续鬼畜网络流…… 首先这题有个显然的做法:bfs预处理出每个起点到每个终点的最短步数,然后直接建边加超级源汇跑费用流即可: 但是这样边数是$n^2$ ...

  2. PHP SOAP 使用示例

    soap_client.php <?php try { $client = new SoapClient( null, array('location' =>"http://lo ...

  3. web 安全主题

  4. NOIP2018提高组省一冲奖班模测训练(二)

    比赛链接 NOIP2018提高组省一冲奖班模测训练(二) 今天发挥正常,昨天不在状态…… 花了很久A了第一题 第二题打了30分暴力 第三题投机取巧输出test1答案(连暴力都不知道怎么打,太弱了) 2 ...

  5. VUE:项目的创建、编写、打包及规范检查

    VUE:项目的创建.编写及打包 项目的创建 使用 vue-cli 创建模板项目(官方提供的脚手架工具) https://github.com/vuejs/vue-cli npm install -g ...

  6. Spring中使用Quartz之MethodInvokingJobDetailFactoryBean配置任务

    Quartz是一个强大的企业级任务调度框架,Spring中继承并简化了Quartz. Spring中使用Quartz的3种方法(MethodInvokingJobDetailFactoryBean,i ...

  7. maven小知识点

    Maven 使用惯例优于配置的原则 .它要求在没有定制之前,所有的项目都有如下的结构: 一个 maven 项目在默认情况下会产生 JAR 文件,另外 ,编译后 的 classes 会放在 basedi ...

  8. HDU 2421

    由算术基本定理N=p1^e1*p2^e2....ps^es,可知一个素的因子个数为(e1+1)*(e2+1)*...*(es+1). 而N的一人因子必定也有n=p1^k1*p2^k2....*ps^k ...

  9. 初识BeeFramework

    由于近期的项目须要,Hybrid开发成为我開始学习的新知识.非常早之前就了解到两个开发框架--BeeFramework 和 Samurai,可是由于本人一直没有闲暇去研究,所以就一直搁置一旁了.近期才 ...

  10. 四种GCC内置位运算函数

    int __builtin_ffs (unsigned int x) 返回x的最后一位1的是从后向前第几位,比方7368(1110011001000)返回4. int __builtin_clz (u ...