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

1703跟某同学得AC的代码几乎都一样了。。。还是WA。。求指点

Posted by severous at 2011-04-05 09:36:38 on Problem 1703
#include<stdio.h>
int d[100000],f[100000],re[500000]={0};//d[]储存敌人,f[]储存朋友。 
void set(int n){//初始化 
	int i;
	for(i=1;i<=n;i++){
		d[i]=0;
		f[i]=i;
	}
}
int find(int i){//找朋友 
 	if(f[i]!=i)
 	f[i]=find(f[i]);
 	return f[i];
 }
void unoin(int rx,int ry){//连接朋友 
	f[rx]=ry;
}
main()
{
	int t,n,m,a,b,i,j,k=0;
	char ch;
	scanf("%d",&t);
	for(i=0;i<=t-1;i++){
		scanf("%d%d",&n,&m);
		set(n);
		for(j=0;j<=m-1;j++){
			getchar();
		scanf("%c%d%d",&ch,&a,&b);
		if(ch=='A'){
			if(find(a)==find(b))//如果有相同的根为朋友。 
			printf("In the same gang.\n");
			else{
				if(d[a]!=0 && d[b]!=0){
				if(find(d[a])==find(b))//如果a的敌人是b的朋友,则 a,b为敌人。 
				printf("In different gangs.\n");
				else//其他为不确定 
				printf("Not sure yet.\n");
				}
				else
				printf("Not sure yet.\n");
			}
			
		}
		else{//ch==D
			if(d[a]!=b && d[a]!=0) 
			unoin(find(d[a]),find(b));
			else{
				if(d[b]!=0 && d[b]!=a)//调试时弄出了D 1 3/D 2 3/A 1 2 
				unoin(find(d[b]),find(a));
			}
			d[a]=b;
			d[b]=a;
		}
      }
	}
}

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