Mai intai trebuie sa te autentifici.

Cod sursa(job #586543)

Utilizator IAmASuperCerealVictor Andrei IAmASuperCereal Data 2 mai 2011 12:11:55
Problema Paduri de multimi disjuncte Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>
#define nmax 100042
#define input "disjoint.in"
#define output "disjoint.out"

using namespace std;

int T[nmax];

void open()
{
	freopen(input,"r",stdin);
	freopen(output,"w",stdout);
}

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

void padurea_intunecata()
{
	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)//faggot
                T[m1]=m2;
        else
            if(m1==m2)
                printf("DA\n");
            else 
				printf("NU\n");
    }
}

int main()
{
	open();
	padurea_intunecata();
    return 0;
}