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

那位同仁给看看为什么一提交就RE啊???痛苦死了!!

Posted by zhenly at 2006-09-30 09:15:09 on Problem 2492
#include<stdio.h>
int diff[2002],same[2002];
int Find(int x, int a);//a==1 stands for diff[], and 0 for same!!
void Union(int x,int y,int a);
void main()
{
	
	int x,y,px,py,i,j,N,n,m,flag;
	scanf("%d",&N);
	for(j=1;j<=N;j++)
	{
		scanf("%d%d",&n,&m);
		flag=0;
		for(i=1;i<=n;i++)
			diff[i]=same[i]=-100000;
		for(i=0;i<m;i++)
		{
			scanf("%d%d",&x,&y);
			if(flag==0)
			{
				if(Find(x,0)==Find(y,0))
					flag=1;
				else
				{
					if(diff[x]==-100000&&diff[y]==-100000)
					{
						Union(x,y,1);
						if(Find(x,1)==x)
							diff[x]=-y;
						else
							diff[y]=-x;
					}
					else
					{
						px=Find(x,1);
						py=Find(y,1);
						if(diff[px]!=-100000)
						{
							if(px!=x)
								Union(px,py,0);
							else
								Union((-diff[px]),py,0);
						}
						if(diff[py]!=-100000)
						{
							if(py!=y)
								Union(py,px,0);
							else
								Union((-diff[py]),px,0);
						}
					}
				}
			}
		}
		if(flag==1)
			printf("Scenario #%d:\nSuspicious bugs found!\n",j);
		else
			printf("Scenario #%d:\nNo suspicious bugs found!\n",j);
	}
}
int Find(int x, int a)
{
	if(a==0)
	{
		if(same[x]<0)
		return x;
	else
		same[x]=Find(same[x],a);
	return same[x];
	}
	else
	{
		if(diff[x]<0)
		return x;
	else
		diff[x]=Find(diff[x],a);
	return diff[x];
	}

}
void Union(int x,int y,int a)
{
	int temp;
	if(x==y)
		return;
	if(a==0)
    {
		temp=same[x]+same[y];
		if(same[x]>same[y])
		{
			same[x]=y;
			same[y]=temp;
		}
		else
		{
			same[y]=x;
			same[x]=temp;
		}
	}
	else
	{
		temp=diff[x]+diff[y];
		if(diff[x]>diff[y])
		{
			diff[x]=y;
			diff[y]=temp;
		}
		else
		{
			diff[y]=x;
			diff[x]=temp;
		}
	}
}

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