| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
又开始不停的RE了In Reply To:为什么不停的超内存 Posted by:dynamic_study at 2009-07-31 15:49:53 #include<iostream>
using namespace std;
#define maxn 100010
int *father=NULL;
void makeset(int n)
{
int i;
father=new int [n+1];
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[5];
cin>>t;
while(t--)
{
cin>>n>>k;
makeset(n);
for(i=0;i<k;i++)
{
cin>>ch;
if(ch[0]=='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[0]=='D')
{
cin>>x>>y;
D(x,y);
}
}
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator