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 qaz123wsx123 at 2018-09-29 10:38:37 on Problem 2492
#include<cstdio>
#include<cstdlib>
#define max 200050
void me(int,int);int gf(int);
int father[max];
int main()
{
    int x,y,times=0;
    scanf("%d",&times);
    for(int j=1;j<=times;j++)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        bool turn=false;
        for(int i=0;i<max;i++)
        {
                father[i]=i;
        }
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d",&x,&y);
            if(x==y)
            	turn=true;
            if(gf(x)!=0&&gf(x)!=20189)
            {    
                if(gf(y)==0)
                {
                    me(20189,x);    
                }
                else if(gf(y)==20189)
                {
                    me(0,x);    
                }
                else if(gf(y)!=0&&gf(y)!=20189)
                {
                    me(0,x);
                    me(20189,y);    
                }
            }
            else if(gf(x)==20189)
            {
                if(gf(y)!=0&&gf(y)!=20189)
                {
                    me(0,y);
                }
                else if(gf(y)==20189)
                {
                    turn=true;
                    //printf("2***");
                }
                else
                {
                    me(0,y);    
                }
            }
            else if(gf(x)==0)
            {
                if(gf(y)!=0&&gf(y)!=20189)
                {
                    me(20189,y);
                }
                else if(gf(y)==0)
                {
                    turn=true;
                    //printf("3***");
                }
                /*if(gx)
                {
                    me(20004,y);    
                }*/
            }
			/*for(int i=1;i<=n;i++)
				printf("%d ",father[i]);*/
        }
        //forest is true or false
        /*for(int i=1;i<max;i++)
        {
            gf(i);    
        }
        int mid=0;
        for(int i=1;i<max;i++)
        {
            if(book[i]==true)
            {
                mid=father[i];
            }    
        }
        for(int i=1;i<max;i++)
        {
            if(book[i]==true)
            {
                if(father[i]!=mid)
                {
                    turn=true;    
                }
            }        
        }*/
        //output
        
        if(turn==false)
        {
            printf("Scenario #%d:\nNo suspicious bugs found!\n\n",j);
        }    
        else
        {
            printf("Scenario #%d:\nSuspicious bugs found!\n\n",j);
        }
        //system("pause");
    }    
}
int gf(int x)
{
    int q,a,z;
    q=x;
    while(father[q]!=q)
    {
        q=father[q];    
    }
    /*z=x;
    while(z!=father[z])
    {
        a=father[z];
        father[z]=q;
        z=a;    
    }*/
    return q;
}
void me(int x,int y)
{
    int fx,fy;
    //fx=gf(x);
    fy=gf(y);
    //printf("00000000\n");
    if(x!=fy)
    {
		//printf("%d %d***\n",fy,x);
        father[fy]=x;    
    }    
}

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