Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求大神帮我看一下为什么WA了.....................................

Posted by heu2013201423 at 2014-05-01 11:53:18 on Problem 1703
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdio>
#define MAXN 100005
using namespace std;
int root[MAXN];
int relation[MAXN];
int find(int n)
{
    int t;
    if(root[n]==n)
        return n;
    else t=find(root[n]);
    root[n]=t;
    relation[n]=(relation[n]+relation[root[n]])%2;
    return t;
}
void inti(int n)
{
    for(int i=0; i<n; i++)
    {
        root[i]=i;
        relation[i]=0;
    }
}
void uni(int a,int b)
{
    int ra=find(a);
    int rb =find(b);
    if(ra==rb)
        return;
    root[b]=a;
    relation[b]=(relation[a]-relation[b]+3)%2;

}
int main()
{
    int n,m,k,a,b;
    char operat;
    while(cin>>k)
    {
        while(k--)
        {
            cin>>m>>n;
            inti(m);
            for(int i=0; i<n; i++)
            {
                cin>>operat;
                scanf("%d%d",&a,&b);
                if(m==2)
                {
                    printf("In different gangs.\n");
                    continue;
                }
                if(operat=='A')
                {
                    if(find(a)!=find(b))
                        printf("Not sure yet.\n");
                    else
                    {
                        if((relation[a]-relation[b]+2)%2==0)
                            printf("In the same gang.\n");
                        else
                            printf("In different gangs.\n");
                    }
                }
                else
                    uni(a,b);
            }
        }
    }
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator