Pagini recente » Cod sursa (job #3281610) | Cod sursa (job #1083947) | Cod sursa (job #1375326) | Cod sursa (job #2041733) | Cod sursa (job #2909384)
#include <bits/stdc++.h>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int N = 100010;
int n,m,T[N],getRoot(int);
int main()
{
f>>n>>m;
for(int i=1;i<=n;i++)
T[i]=i;
for(;m;m--)
{
int op,x,y;
f>>op>>x>>y;
x=getRoot(x);
y=getRoot(y);
if(op==1)
T[x]=y;
else
if(x==y)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];
}