Pagini recente » Monitorul de evaluare | Rating Mama lui Vlad (DS2010DS) | Istoria paginii utilizator/casandrescu | Cod sursa (job #2697280) | Cod sursa (job #2240140)
#include <bits/stdc++.h>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int N = 100000;
int n,m,i,T[N],c,x,y,rx,ry,get_root(int);
int main()
{
f>>n>>m;
for(i=1;i<=n;i++)
T[i]=i;
for(;m;m--)
{
f>>c>>x>>y;
rx=get_root(x);
ry=get_root(y);
if(c==1)
T[rx]=ry;
else
if(rx==ry)
g<<"DA\n";
else
g<<"NU\n";
}
return 0;
}
int get_root(int nod)
{
if(nod==T[nod])return nod;
T[nod]=get_root(T[nod]);
return T[nod];
}