Cod sursa(job #664866)

Utilizator tomaAndrei Toma toma Data 21 ianuarie 2012 00:14:36
Problema Paduri de multimi disjuncte Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include<stdio.h>
int T[100002],N,M,i,t,y,x;
int tt(int x)
{
	while (x!=T[x]) x=T[x];
	return x;
}
int main()
{
	freopen("disjoint.in","r",stdin);
	freopen("disjoint.out","w",stdout);
	scanf("%d%d",&N,&M);
	for (i=1;i<=N;i++) T[i]=i;
	for (i=1;i<=M;i++)
	{
		scanf("%d%d%d",&t,&x,&y);
		x=tt(x);y=tt(y);
		if (t==1) T[x]=y;
		else if (y==x) printf("DA\n");
		else printf("NU\n");
	}
}