Pagini recente » Cod sursa (job #2093472) | Cod sursa (job #501684) | Cod sursa (job #2635467) | Cod sursa (job #3188402) | Cod sursa (job #2547176)
#include <bits/stdc++.h>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int N = 100010;
int n,m,o,x,y,T[N],getRoot(int);
int main()
{
f>>n>>m;
for(int i=1;i<=n;i++)
T[i]=i;
for(;m;m--)
{
f>>o>>x>>y;
int rx=getRoot(x);
int ry=getRoot(y);
if(o==1)
T[rx]=ry;
else
if(rx==ry)
g<<"DA\n";
else
g<<"NU\n";
}
return 0;
}
int getRoot(int nod)
{
if(T[nod]==nod)return nod;
T[nod]=getRoot(T[nod]);
return T[nod];
}