A Bug's Life(带权并查集)
来源:互联网 发布:fc2的域名设置 编辑:程序博客网 时间:2024/06/14 04:44
hdu1829 这是一道比较简单 好理解的并查集
#include <iostream>#include <stdio.h>#include <math.h>#include <algorithm>#include <queue>#include <stack>#include <vector>#include <string>#include <string.h>#include <map>#include <set>using namespace std;int f[2001],r[2001];int n,k;int findfa(int x){ if(x==f[x]) { return x; } else { int t=f[x]; f[x]=findfa(f[x]); r[x]=(r[x]+r[t]+2)%2; return f[x]; }}void bing(int x,int y){ int tx=findfa(x),ty=findfa(y); if(tx!=ty) { f[ty]=tx; r[ty]=(r[x]-r[y]+1+2*2)%2; }}int istrue(int x,int y){ if(x>n||y>n||x==y) { return 0; } int tx=findfa(x),ty=findfa(y); if(tx!=ty)return 1; else { if(r[x]==(r[y]+1)%2) { return 1; } else return 0; }}int main(){ int i,t,ans,tt=1,x,y; scanf("%d",&t); while(t--) { for(i=1;i<=2001;i++) { f[i]=i;r[i]=0; } scanf("%d%d",&n,&k); ans=0; for(i=1;i<=k;i++) { scanf("%d%d",&x,&y); if(istrue(x,y)) { bing(x,y); } else ans++; } printf("Scenario #%d:\n",tt++); if(ans!=0)printf("Suspicious bugs found!\n"); else printf("No suspicious bugs found!\n"); printf("\n"); } return 0;}
0 0
- A Bug's Life(带权并查集)
- A bug's life(带权并查集)
- Poj 2492 A Bug's Life(带权并查集)(水)
- poj 2492 A Bug's Life(带权并查集)
- hdoj--1829--A Bug's Life(带权并查集)
- 【POJ】2492 - A Bug's Life(带权并查集)
- poj 2492 A Bug's Life(带权并查集)
- POJ 2492-A Bug's Life(带权并查集)
- 【poj 2492】A Bug's Life (带权并查集)
- HDU 1829 A Bug's Life(带权并查集)
- HDU 1829 A Bug‘s Life 带权并查集&&带偏移量的写法
- A Bug's Life 并查集
- 并查集 A Bug's Life
- A Bug's Life 并查集
- POJ-2492 A Bug's Life 带权并查集
- poj 2492 A Bug's Life(带权并查集)
- poj 2492 A Bug's Life(带权并查集)
- hdu1829——A Bug's Life 种类、带权并查集 裸题
- Codeforces Round #121 (Div. 2)
- clion 1.05 Mac 安装与破解
- JSON 对象未定义错误
- ip别名及其在tcp压力测试时候的作用
- js简单封装ajax场景
- A Bug's Life(带权并查集)
- 关于linux服务配置的问题 starting MySQL.Manager of pid-file quit without updating fi[failed]
- 【Android应用开发技术:用户界面】SurfaceView
- 20150729 DOM事件探秘
- 百度uri 跳转
- 如果让我重新设计一款Android App
- WIN10安装与升级的方法
- 软件开发工具和数据结构导论
- 暑假集训第三周第二阶段 搜索 J - 放苹果