poj 2492 A Bug's Life 并查集

来源:互联网 发布:音效软件下载 编辑:程序博客网 时间:2024/06/05 06:12

裸的并查集咯

ACcode:

#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define maxn 100010int myset[maxn];int find_x(int x){    if(myset[x]==-1)return x;    return myset[x]=find_x(myset[x]);}int main(){    int loop,tot=1;    scanf("%d",&loop);    while(loop--){        if(tot>1)printf("\12");        int n,m;        scanf("%d%d",&n,&m);        memset(myset,-1,sizeof(myset));        int flag=0;        while(m--){            int a,b;            scanf("%d%d",&a,&b);            if(find_x(a)!=find_x(b)&&find_x(a)!=find_x(b+n)){                myset[find_x(a)]=find_x(b+n);                myset[find_x(b)]=find_x(a+n);            }            else if(find_x(a)==find_x(b))flag=1;        }        printf("Scenario #%d:\n%s bugs found!\n",tot++,flag==0?"No suspicious":"Suspicious");    }    return 0;}/**/


0 0
原创粉丝点击