Cod sursa(job #2118555)

Utilizator AlexVulpoiuAlexandru Vulpoiu AlexVulpoiu Data 30 ianuarie 2018 19:08:35
Problema Paduri de multimi disjuncte Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <cstdio>
using namespace std;
int n,m,x,y,op,t[100001];
int main()
{
    freopen("disjoint.in","r",stdin);
    freopen("disjoint.out","w",stdout);
    scanf("%d %d\n",&n,&m);
    for(x=1;x<=n;x++)
        t[x]=x;
    while(m)
    {
        scanf("%d %d %d\n",&op,&x,&y);
        while(x!=t[x])
            x=t[x];
        while(y!=t[y])
            y=t[y];
        if(op==1 && x!=y)
            t[x]=y;
        else
            if(op==2)
                if(x==y && x)
                    printf("DA\n");
                else
                    printf("NU\n");
        m--;
    }
    return 0;
}