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

who can check this code for me ?it's confusing....i always got Runtime Error.....

Posted by Standard at 2006-03-17 12:58:35 on Problem 1703
#include<stdio.h>
#include<string.h>

int f[100010],d[100010];

int find(int v)
{
	int t;
	if(f[v]==-1)return v;
	t=find(f[v]);
	d[v]+=d[f[v]];
	return f[v]=t;
}
int main()
{
	int test,cnt;
	char name[10];
	int len;
	int a,b,x,y;
	//freopen("in","r",stdin);
	scanf("%d",&test);
	while(test-->0)
	{
		scanf("%d%d",&len,&cnt);
		for(int i=0;i<=len;i++)f[i]=-1,d[i]=0;
		while(cnt-->0)
		{
			scanf("%s%d%d",name,&a,&b);
			x=find(a),y=find(b);
			if(name[0]=='A')
			{
				if(x==y)
				 printf("%s\n",(d[a]-d[b])%2!=0? "In different gangs.":"In the same gang.");
				else
				 printf("Not sure yet.\n");
			}else if(name[0]=='D')
			{
				f[y]=x;
				d[y]=d[a]-d[b]+1;				
			}
		}
	}	
}

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