Cod sursa(job #2200591)

Utilizator PushkinPetolea Cosmin Pushkin Data 1 mai 2018 22:31:56
Problema Paduri de multimi disjuncte Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int m, t[100002];
inline int tata(int x)
{
    while(t[x]!=0)
        x=t[x];
    return x;
}
int main()
{
    int op, x, y;
    f>>m>>m;
    while(f>>op>>x>>y)
    {
        x=tata(x);
        y=tata(y);
        if(op==1)
            t[x]=y;
        else if(x==y)
                g<<"DA\n";
             else
                g<<"NU\n";
    }
    return 0;
}