Pagini recente » Cod sursa (job #2661271) | Cod sursa (job #2328295) | Cod sursa (job #1503642) | Cod sursa (job #2379110) | Cod sursa (job #2042832)
#include <bits/stdc++.h>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int N = 100010;
int n,q,o,x,y,T[N],get_root(int);
int main()
{
f>>n>>q;
for(int i=1; i<=n; i++)
T[i]=i;
for(;q;q--)
{
f>>o>>x>>y;
x=get_root(x);
y=get_root(y);
if(o==1)
T[x]=y;
else
x==y?g<<"DA\n":g<<"NU\n";
}
return 0;
}
int get_root(int nod)
{
if(T[nod]==nod)
return nod;
T[nod]=get_root(T[nod]);
return T[nod];
}