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

为什么不停的超内存

Posted by dynamic_study at 2009-07-31 15:49:53 on Problem 1703
#include<iostream>
using namespace std;
#define maxn 100000
int father[maxn];
void makeset(int n)
{
	int i;
	for(i=1;i<=n;i++)
	   father[i]=0;
}

int findset(int x)
{
	if(father[x]!=x)
		father[x]=findset(father[x]);
	return father[x];
}
void D(int x,int y)
{
	int f1,f2;
	if(x==y)
		return ;
	f1=findset(x);
	f2=findset(y);
	if(f1==0&&f2==0)
	{
		father[x]=1;
		father[y]=2;
	}
	else if(f1==0&&f2!=0)
	{
		if(f2==1)
			father[x]=2;
		else if(f2==2)
			father[x]=1;
	}
	else if(f1!=0&&f2==0)
	{
		if(f1==1)
			father[y]=2;
		else if(f1==2)
			father[y]=1;

	}
	else
		return ;
}

int main()
{
	int t,n,k,i,f1,f2,x,y;
	char ch;
	cin>>t;
	while(t--)
	{
		cin>>n>>k;
		makeset(n);
		for(i=0;i<k;i++)
		{
			cin>>ch;
			if(ch=='A')
			{
				cin>>x>>y;
				f1=findset(x);
				f2=findset(y);
				if(f1==0||f2==0)
				{cout<<"Not sure yet."<<endl;continue;}
				else if(f1==f2)
				{cout<<"In the same gang."<<endl;continue;}
				else if(f1!=f2)
				{cout<<"In different gangs."<<endl;continue;}
			}
			else if(ch=='D')
			{
				cin>>x>>y;
				D(x,y);
			}
		}
	}
	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