Cod sursa(job #586889)

Utilizator taseTanase Alexandru tase Data 3 mai 2011 10:22:00
Problema Paduri de multimi disjuncte Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <stdio.h>
#define nmax 100042
using namespace std;

int f[nmax];

inline int multime(int nod)
{
    while(f[nod])
        nod=f[nod];
    return nod;
}

void padure()
{
	int n,t,x,y,op,m1,m2;
    scanf("%d%d",&n,&t);
    while(t--)
    {
        scanf("%d%d%d",&op,&x,&y);
        m1=multime(x);
        m2=multime(y);
        if(op==1)
                f[m1]=m2;
        else
            if(m1==m2)
                printf("DA\n");
            else 
				printf("NU\n");
    }
}

int main()
{
	freopen("disjoint.in","r",stdin);
	freopen("disjoint.out","w",stdout);
	padure();
    return 0;
}