1829 A Bug's Life
A Bug's Life
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9223 Accepted Submission(s): 2965
Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their interactions were easy to identify, because numbers were printed on their backs.
Problem
Given a list of bug interactions, decide whether the experiment supports his assumption of two genders with no homosexual bugs or if it contains some bug interactions that falsify it.
Huge input,scanf is recommended.
#include<stdio.h>
#include<string.h>
int f[];
int dis[]; int find(int x)
{
int t;
if(f[x]==x)
return x; t=find(f[x]);
dis[x]=(dis[x]+dis[f[x]])%;
f[x]=t;
return t; } int make(int x,int y)
{
int a=find(x);
int b=find(y);
if(a==b)
{
if(dis[x]==dis[y])
return ;
return ;
} f[a]=b;
dis[a]=(dis[x]+dis[y]+)%;
return ; } int main()
{
//freopen("in.txt","r",stdin);
int t,count=;
int n,m;
int i,a,b,flag;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(dis,,sizeof(dis)); for(i=;i<=n;i++)
f[i]=i; flag=;
for(i=;i<m;i++)
{
scanf("%d%d",&a,&b);
if(make(a,b))
{
flag=;
}
} printf("Scenario #%d:\n",count++);
if(flag)
printf("Suspicious bugs found!\n");
else
printf("No suspicious bugs found!\n");
printf("\n");
}
return ;
}
1829 A Bug's Life的更多相关文章
- HDU 1829 A Bug's Life (种类并查集)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1829 A Bug's Life Time Limit: 15000/5000 MS (Java/Oth ...
- hdu 1829 A Bug's Life(分组并查集(偏移量))
A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu - 1829 A Bug's Life (并查集)&&poj - 2492 A Bug's Life && poj 1703 Find them, Catch them
http://acm.hdu.edu.cn/showproblem.php?pid=1829 http://poj.org/problem?id=2492 臭虫有两种性别,并且只有异性相吸,给定n条臭 ...
- 【进阶——种类并查集】hdu 1829 A Bug's Life (基础种类并查集)TUD Programming Contest 2005, Darmstadt, Germany
先说说种类并查集吧. 种类并查集是并查集的一种.但是,种类并查集中的数据是分若干类的.具体属于哪一类,有多少类,都要视具体情况而定.当然属于哪一类,要再开一个数组来储存.所以,种类并查集一般有两个数组 ...
- hdu 1829 A Bug's Life(并查集)
A Bu ...
- HDU 1829 - A Bug's Life
Problem Description Background Professor Hopper is researching the sexual behavior of a rare species ...
- HDU 1829 A Bug's Life 【带权并查集/补集法/向量法】
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
- hdoj 1829 A bug's life 种类并查集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1829 并查集的一个应用,就是检测是否存在矛盾,就是两个不该相交的集合有了交集.本题就是这样,一种虫子有 ...
- HDU 1829 A Bug's Life(种类并查集)
思路:见代码吧. #include <stdio.h> #include <string.h> #include <set> #include <vector ...
随机推荐
- U-Boot--配置过程分析
arm核:arm920t 2410 uboot版本:u-boot1.1.6 通过readme可以知道配置执行make smdk2410_config命令. 顶层Makefile : smdk24 ...
- Android Audio Play Out Channel
1: 7嘴8舌 扬声器, 耳机, 和听筒 就是通过: audiomanager.setmode(AudioManager.MODE_IN_COMMUNICATION)audiomanager.setS ...
- 图片剪裁上传插件 - cropper
图片剪裁上传插件 - cropper <style> .photo-container{float: left;width: 300px;height: 300px;} .photo-co ...
- 【Qt】QSettings介绍【转】
简介 QSettings类提供了持久的跨平台应用程序设置. 用户通常期望应用程序记住它的设置(窗口大小.位置等)所有会话.这些信息通常存储在Windows系统注册表,OS X和iOS的属性列表文件中. ...
- 比较不错的JS 曲线图
fashion chart falsh文件支持,无需考虑兼容 Highcharts(纯JS,很漂亮 效果很好) Highcharts是一个制作图表的纯Javascript类库,主要特性如下: 兼容 ...
- Delphi XE5教程8:使用Delphi命名空间
// Project file declarations... //项目文件声明… program MyCompany.ProjectX.ProgramY; // Unit source file d ...
- Linq中延迟查询和立即查询
//立即查询 public static void NowExecute() { var results = new int[]{5,4,3,2,1,6,7,8,9,0 }; int i = 0; v ...
- 第29章 项目10:DIY街机游戏
1.问题 "Self-Defense Against Fresh Fruit":军士长指挥自己的士兵使用自我防御战术对抗以石榴.芒果.青梅和香蕉等新鲜水果入侵者.防御战术包括使用枪 ...
- hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少 ...
- DC-EPC小结
今晚上修完了最后2个学时的EPC(课程主页),这意味着本学期的DC和共20个学时的EPC到此结束,这有可能是我人生中最后一次上英语课. Tom是我DC课的老师,EPC起于Tom和Micheal的Deb ...