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 marvion at 2007-05-08 20:58:12 on Problem 1988
In Reply To:TLE///////有谁帮我看看 Posted by:BJ051155 at 2007-05-08 17:03:13
> #include <stdio.h>
> 
> void main()
> {
> 	int p,x,y,b[30001],u[30001];
> 	bool sign;
> 	scanf("%d",&p);
> 	for(int i=1;i<=30000;i++)
> 		u[i]=b[i]=0;
> 	char oper;
> 	while(p--)
> 	{
> 		scanf("%c",&oper);
> 		scanf("%c",&oper);
> 		if(oper=='M')
> 		{
> 			sign=1;
> 			scanf("%d%d",&x,&y);
> 			int t=x,f=y;
> 			while(sign&&b[x])
> 			{
> 				if(x==y)
> 					sign=0;
> 				x=b[x];
> 			}
> 			if(x==y)
> 				sign=0;
> 			while(sign&&u[y])
> 			{
> 				if(t==y)
> 					sign=0;
> 				y=u[y];
> 			}
> 			if(t==y)
> 					sign=0;
> 			if(sign)
> 			{
> 				b[x]=y;
> 				u[y]=x;
> 			}
> 		}
> 		else
> 		{
> 			int count=0;
> 			scanf("%d",&x);
> 			while(b[x])
> 			{
> 				count++;
> 				x=b[x];
> 			}
> 			printf("%d\n",count);
> 		}
> 	}
> 
> }

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