hdu----(3118)Arbiter(构造二分图)
Arbiter
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 800 Accepted Submission(s): 410
Problem Description
Arbiter is a kind of starship in the StarCraft science-fiction series. The Arbiter-class starship is a Protoss warship specializing in providing psychic support. Arbiters were crewed exclusively by Judicators; unlike other warships that were manned predominantly by Templar. The Judicator used the Arbiter as a base to provide support using space-time manipulation. Arbiters could weaken space-time, tearing rifts in the fabric of space-time, creating a vortex linking another location to the Arbiter’s location. This could be used to move personnel over long distances between stars. In the meantime of widely used Arbiter to transfer, KMXS, the captain of one Arbiter, was warning that some person had got a serious mental disorder after the trip on his Arbiter. By using mice as model animals, he found the sake, it’s because of chirality! Every person has chirality, either left-handed or right-handed. Actually all the persons must live with the food which has the same chirality. When one person took Arbiter from one star to another one, his chirality will be changed (from left-handed to right-handed or from right-handed to left-handed). If a person took a long trip and finally got back to his own star, however, his chirality might be changed to the opposite state other than his original, which would cause fatal mental disorder, or even death. KMXS has the channels map among the starts and he need to prohibit minimum number of channels from traveling so that wherever a person starts his traveling from when he gets his original star he’ll be safe. KMXS turns to your help.
Input
The first line of input consists of an integer T, indicating the number of test cases. The first line of each case consists of two integers N and M, indicating the number of stars and the number of channels. Each of the next M lines indicates one channel (u, v) which means there is a bidirectional channel between star u and star v (u is not equal to v).
Output
Output one integer on a single line for each case, indicating the minimum number of channels KMXS must prohibit to avoid mental disorder. Constraints 0 < T <= 10 0 <= N <= 15 0 <= M <= 300 0 <= u, v < N and there may be more than one channel between two stars.
Sample Input
1 3 3 0 1 1 2 2 0
Sample Output
1
Source
2009 Asia Wuhan Regional Contest Online
这道题的意思:
Arbiter
“仲裁者”是《星际争霸》科幻系列中的一种太空船。仲裁者级太空船是神族的战船,专门提供精神力支援。不像其他战船的人员主要是战士阶级,仲裁者所承载的都是统治阶级。统治者以仲裁者为基地,用时空操控来提供支援。
仲裁者可以克服时空限制,撕裂时空,产生裂缝,制造涡洞,把另一个空间连接到仲裁者所在空间,可以用来运送人员,跨越长途星际。
正当仲裁者广泛用于运输的时候,一艘仲裁者的船长 KMXS 发出警告,有些人员在他的船上完成旅程之后,得到严重的精神错乱。他用小白鼠做动物实验,找到了原因,是生物化学中的“手性”!
每个人 都有手性,是左手性或者右手性。事实上,所有人的生存都必须依靠相同手性的食物。一个人乘坐仲裁者从一个星球到另一个星球的时候,他的手性会改变,(从左 手性变成右手性,或者从右手性变成左手性。)如果一个人经过长途旅行,最后回到自己的星球,可是他的手性却可能改变成跟原来的相反,那就会造成致命的精神 错乱,甚至死亡。
KMXS 拥有星球之间的航道图。他需要禁止通过航道的最少数目,以致无论一个人从哪里出发,当他回到自己的星球,会是安全的。KMXS请求你的帮助。
Input
第一行输入有一个整数 T,表示测试用例的数目。
每个用例的第一行有两个整数 N 和 M,表示星球的数目和航道的数目。随后的 M 行表示航道,每个 (u, v) 代表在星球 u 和星球 v 之间有一条双向的航道(u 不等于 v)。
Output
每个测试用例的结果输出一行,用一个整数表示KMXS为了要避免人们精神错乱, 必须禁止的最少航道数目。
Constraints
0 < T <= 10
0 <= N <= 15 0 <= M <= 300
0 <= u, v < N在两个星球之间可以有超过一条航道
Sample Input
13 30 11 22 0
Sample Output
1
很明显: 这个意思是,可以从任意一个星球,到大另一个星球,但是每个星球都有手性.....
要我们求出,对于任何一个星球出发都不能通过奇数次传递回到该星球...也就是不能形成奇数环..
而我们知道,二分图的充要条件是: 至少存在两个顶点,每一个点的回路的长度都是偶数...
所以只需进行擦边,来构成二分图就可以了.,...
代码:
1 #include<cstring>
2 #include<cstdio>
3 const int maxn=305;
4 int aa[maxn],bb[maxn];
5 int n,m;
6 int main(){
7 int test;
8 //freopen("test.in","r",stdin);
9 scanf("%d",&test);
10 while(test--){
11 scanf("%d%d",&n,&m);
12 for(int i=0;i<m;i++){
13 scanf("%d%d",aa+i,bb+i);
14 }
15 int ans=m+2;
16 for(int i=0;i<(1<<n);i++) //2^n种情况,对于每一个星球都可以两种情况要么为左,要么为右
17 {
18 int cnt=0;
19 for(int j=0;j<m;j++){
20 if(((i>>aa[j])%2)==((i>>bb[j])%2)) //属于同一个世界,说明呵呵存在奇数环
21 cnt++;
22 }
23 if(ans>cnt)ans=cnt;
24 }
25 printf("%dn",ans);
26 }
27 return 0;
28 }
- Django——model基础
- java学习:日期的运算
- ORACLE:写Function时,传入参数变量名的注意事项
- spring boot 登录注册 demo (二) -- 数据库访问
- spring boot 登录注册 demo (三) -- 前后端传递
- python装饰器大详解
- spring boot 登录注册 demo (四) -- 体验小结
- jenkins 时区设置
- 什么样的密码才是安全的?
- MAC本遭遇ARP攻击的处理办法
- nodejs 语法学习(持续更新)
- Django——模板层(template)(模板语法、自定义模板过滤器及标签、模板继承)
- - Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side
- Django - - - -视图层之视图函数(views)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Android内存优化 | LeakCanary/Profiler & 非静态内部类耗时操作 实战分析
- 使用keycloak实现k8s用户权限的统一管理
- python魔法方法是什么
- 如何同步上游分支代码?
- 在 Pycharm 中安装及使用 Jupyter (图文详解)
- 【经验分享】如何使用keras进行多主机分布式训练
- 分享一种接口的日志格式
- Python 基础(二):基本语句
- javaScript代码飘红报错看不懂?读完这篇文章再试试!
- Synchronized简述
- PythonforResearch | 2_数据处理
- 程序员过关斩将--Http请求中如何保持状态?
- 如何有效恢复误删的HDFS文件
- 别再用OFFSET和LIMIT分页了
- 别再用大小比较时间了