Pagini recente » Diferente pentru problema/ismquery intre reviziile 4 si 29 | Borderou de evaluare (job #2675468) | Cod sursa (job #2495986) | Borderou de evaluare (job #2487584) | Cod sursa (job #2433503)
#include <bits/stdc++.h>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int N = 100010;
int n,q,T[N],x,y,rx,ry,c,getRoot(int);
int main()
{
f>>n>>q;
for(int i=1;i<=n;i++)T[i]=i;
for(;q;q--)
{
f>>c>>x>>y;
rx=getRoot(x);
ry=getRoot(y);
if(c==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];
}