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:WA ,RE,TLE的统统往这里看~~~~~~

Posted by 1066358949 at 2014-06-02 09:14:58 on Problem 1703
In Reply To:WA ,RE,TLE的统统往这里看~~~~~~ Posted by:rdy2012 at 2013-01-25 20:33:03
> /*
> 这道题告诉我们,有什么事找老大说去。。。
> 还有,我是卖切糕的。。
> */
> 
> # include<cstdio>
> # include<cstring>
> using namespace std;
> 
> # define N 100005
> 
> int father[N],Rank[N],opp[N];   //opp表示它的敌对势力  =。=
> 
> void make_set(int n)
> {
> 	int i;
> 	for(i=1;i<=n;i++)
> 	{
> 		father[i]=i;
> 		opp[i]=Rank[i]=0;    //刚出道,没有敌对势力
> 	}
> 	
> }
> 
> int find(int r)            //小弟全部得跟老大姓
> {
> 	if(father[r]!=r)
> 		father[r]=find(father[r]);
> 	return father[r];
> }
> 
> void merge(int a,int b)   //a,b成一家
> {
> 	a=find(a);
> 	b=find(b);
> 	if(a==b)
> 		return;
> 	if(Rank[a]>Rank[b])
> 		father[b]=a;
> 	else
> 	{
> 		father[a]=b;
> 		if(Rank[a]=Rank[b])
> 			Rank[b]++;
> 	}
> }
> 
> int main()
> {
> 	int i,n,m,a,b,t,head_a,head_b;
> 	char op[10];
> 	scanf("%d",&t);
> 	while(t--)
> 	{
> 		scanf("%d%d",&n,&m);
> 		make_set(n);
> 		for(i=1;i<=m;i++)
> 		{
> 			scanf("%s%d%d",op,&a,&b);
> 			head_a=find(a); //找出他们各自的老大
> 			head_b=find(b);  
> 
> 			if(op[0]=='A')
> 			{
> 				if(head_a==head_b)        //同一个势力,兄弟见面了
> 					printf("In the same gang.\n");   //哥俩好呀!					
> 				else if(head_a==find(opp[head_b]))    //什么,你不认识我? |-- 没关系,我认识你们一个人的老大就是他(我情敌的老大就是你,所以你就是我敌人)
> 					printf("In different gangs.\n");    //去你丫的!!!
> 			    else                                
> 					printf("Not sure yet.\n");  //大哥,我什么都不知道啊
> 			}
> 			else
> 			{	
> 				if(opp[a]==0)            //没有敌对势力,毕竟刚出道嘛
> 					opp[a]=head_b;       //他的敌对势力就是b所在的势力
> 				if(opp[b]==0)            //纯洁的孩子啊
> 					opp[b]=head_a;       //就看你不爽,咋地~~~~
> 				merge(a,opp[head_b]);    //加到自己的势力去,投靠老大去了(自己的势力就是b敌对的势力)
> 				merge(b,opp[head_a]);    //大哥,我来了。。。。。			
> 
> 			}	
> 		}
> 	}
> 	return 0;
> }

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