POJ 1703 Find them,Catch them

#include
#include
#include
const int MAXN=200020;
int n,m;
int set[MAXN];
int set_find(int d)
{
     
    if(set[d]<0)
        return d;
    else
        return set[d]=set_find(set[d]);
}
int main()
{
     
    int loop;
    scanf("%d",&loop);
    while(loop--)
    {
     
        scanf("%d%d",&n,&m);
        memset(set,-1,sizeof(set));
        for(int i=0;i<m;i++)
        {
     
            int a,b;
            char s[5];
            scanf("%s%d%d",s,&a,&b);
            if(s[0]=='A')
            {
     
                if(set_find(a)!=set_find(b)&&set_find(a)!=set_find(b+n))
                    printf("Not sure yet.
"
); else if(set_find(a)==set_find(b)) printf("In the same gang.
"
); else printf("In different gangs.
"
); } else{ if(set_find(a)!=set_find(b+n)) { set[set_find(a)]=set_find(b+n); set[set_find(b)]=set_find(a+n); } } } } return 0; }

좋은 웹페이지 즐겨찾기