[ create a new paste ] login | about

Link: http://codepad.org/spRW6B3a    [ raw code | fork ]

didyxdi - C++, pasted on Sep 3:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<cstring>
#include<cctype>
#include<string>
#include<string.h>
#include<list>
using namespace std;

int loop;
int n,m;
int father[200020];

void init()
{
	for(int i=1;i<=2*n;i++)
	father[i]=i;
}

int find(int x)
{
	return father[x]==x ? x : father[x]=find(father[x]); 
}

int main()
{
	while(scanf("%d",&loop)!=EOF)
	{
	//	cout<<"loop:"<<loop<<endl;
		while(loop--)
		{
		//	getchar();
			scanf("%d %d",&n,&m);
		//	getchar();
			init();
			for(int i=1;i<=m;i++)
			{
				int x,y;char c[5];
				scanf("%s%d%d",c,&x,&y);
				getchar();
			//	cout<<"*"<<c<<" "<<x<<" "<<y<<endl;
				if(c[0]=='A')
				{
					if(find(x)!=find(y+n) && find(x)!=find(y))
					printf("Not sure yet.\n");
					else if(find(x)==find(y))
					printf("In the same gang.\n"); 
					else printf("In different gangs.\n");
				}
				else
				{
					if(find(x)!=find(y+n))
					{
						father[find(x)]=find(y+n);
						father[find(x+n)]=find(y);
					}
				}
			}
		//	cout<<"-----------------"<<endl;
		}
	}
	return 0;
}


Output:
No errors or program output.


Create a new paste based on this one


Comments: