Cod sursa(job #542516)

Utilizator blastoiseZ.Z.Daniel blastoise Data 26 februarie 2011 14:27:18
Problema Gossips Scor 0
Compilator cpp Status done
Runda Romanian Master in Mathematics and Sciences 2011, Ziua 2 Marime 0.73 kb
#include <stdio.h>
#include <string.h>
#include <set>

using namespace std;

int x,y,z,N,M,Q,i,s,ok;
int T[100100];

set<int> v[100000];
set<int>::iterator it;

int main()
{
	freopen("gossips.in","r",stdin);
	freopen("gossips.out","w",stdout);

	scanf("%d%d%d",&N,&M,&Q);

	memset(T,0,sizeof(T));

	for(i=1;i<=M;i++)
	{
		scanf("%d%d",&x,&y);
		T[y]=x;
	}

	for(i=1;i<=Q;i++)
	{
		scanf("%d%d%d",&s,&x,&y);

		if(s==2)
		{
			while(T[x]!=0) x=T[x];

			z=y;
			while(z!=0)
			{
				v[x].insert(z);
				z=T[z];
			}
		}
		else
		{
			ok=0;
			while(T[x]!=0) x=T[x];

			it=v[x].find(y);
			if(it!=v[x].end()) ok=1;

			if(ok==0) printf("NO\n");
			else printf("YES\n");
		}
	}

	return 0;
}