hdu1829 A Bug's Life(并查集)
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAX=2000;
int pre[2*MAX+5];
bool mark;
void init(int n){
int i;
for(i=1;i<=MAX+n;i++) pre[i]=i;
mark=true;
}
int root(int x){
if(x!=pre[x]){
pre[x]=root(pre[x]);
}
return pre[x];
}
void merge(int x,int y){
int fx,fy;
fx=root(x);
fy=root(y-MAX);
if(fx==fy) {
mark=false;
return;
}
fy=root(y);
if(fx!=fy){
pre[fx]=pre[fy];
}
}
int main()
{
int t,i,n,m,x,y,k;
scanf("%d",&t);
for(i=1;i<=t;i++){
scanf("%d%d",&n,&m);
init(n);
for(k=1;k<=m;k++){
scanf("%d%d",&x,&y);
if(mark){
merge(x,y+MAX);
merge(y,x+MAX);
}
}
printf("Scenario #%d:\n",i);
if(mark){
printf("No suspicious bugs found!\n");
}else{
printf("Suspicious bugs found!\n");
}
printf("\n");
}
return 0;
}
hdu1829 A Bug's Life(并查集)的更多相关文章
- HDU-1829 A Bug's Life。并查集构造,与POJ1709异曲同工!
A Bug's Life Find them, Catch them 都是并查集构造的题,不久前 ...
- poj2492--A Bug's Life(并查集变形)
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 28703 Accepted: 9350 De ...
- POJ 2492 A Bug's Life【并查集高级应用+类似食物链】
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
- 【POJ】2492 A bug's life ——种类并查集
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 28211 Accepted: 9177 De ...
- POJ 2492 A Bug's Life (并查集)
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
- poj2492 A Bug's Life【并查集】
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assume ...
- A Bug's Life(加权并查集)
Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs ...
- POJ2492 A Bug's Life —— 种类并查集
题目链接:http://poj.org/problem?id=2492 A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Su ...
- POJ_2492 A Bug's Life 【并查集】
一.题面 POJ2492 二.分析 并查集判断类别的题目感觉套路都差不多. 还是先判断在不在一个集合里,在一个集合里才能判断是否同类. 若不在一个集合里则需要将这两个点联系起来. 关于联系起来后关系的 ...
随机推荐
- golang 获取statuscode
最近日志打印的时候需要打印状态码,但是因为interface的原因直接获取失败,http.Request里面的response不知道怎么使用,所以就自己重写writeheader,write来截取st ...
- android view、viewgroup 事件响应拦截处理机制
文章中会用到部分网络资源,首先将原作者的链接附上. 但是还是会附上数量较大的关于此部分内容的自己的思考. ----------------------------------------------- ...
- α&β测试的定义及结束的标准
α测试在系统开发接近完成时对应用系统的测试:测试后仍然会有少量的设计变更.这种测试一般由最终用户或其他人员完成,不能由程序或测试员完成. β测试当开发和测试根本完成时所做的用例,最终的错误和问题需要在 ...
- SHRINK SPACE Command : Online Segment Shrink for Tables, LOBs and IOTs
ORACLE-BASE - ALTER TABLE ... SHRINK SPACE Command : Online Segment Shrink for Tables, LOBs and IOTs ...
- Spring Boot (14) 数据源配置原理
数据源配置源码 这里截取org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration的部分源码,主要介绍Tomcat和Hika ...
- windows下react-native搭建环境
第一步:安装Java 1.下载JDK,选择适应自己的机型:官网地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downl ...
- OpenCv:椭圆上点的计算方程
椭圆 椭圆(Ellipse)是平面内到定点F1.F2的距离之和等于常数(大于|F1F2|)的动点P的轨迹,F1.F2称为椭圆的两个焦点.其数学表达式为: ...
- Matlab矩阵填充--Matlab interp2
Matlab interp2 为Matlab的矩阵填充函数, 填充关系: x=1:11; y=1:13; x1=1:0.1:12; y1=1:0.1:14; [x2,y2]=meshgrid(x1,y ...
- 【sqli-labs】 less4 GET - Error based - Double Quotes - String (基于错误的GET双引号字符型注入)
提交id参数 加' http://localhost/sqli/Less-4/?id=1' 页面正常,添加" http://localhost/sqli/Less-4/?id=1" ...
- 【转载】使用IntelliJ IDEA提示找不到struts-default文件
创建strus,参考文如下: https://blog.csdn.net/u010358168/article/details/79769137 使用IntelliJ IDEA创建struts2工程时 ...