Pagini recente » Cod sursa (job #1116549) | Cod sursa (job #1083544) | Cod sursa (job #2687927) | Cod sursa (job #1878100) | Cod sursa (job #2874876)
#include <bits/stdc++.h>
using namespace std;
ifstream in ("disjoint.in");
ofstream out ("disjoint.out");
int n,m,T[100001],op,x,y;
int Find(int nod)
{
int rad=nod;
while (T[rad]!=0)
{
rad=T[rad];
}
int aux;
while (nod!=rad)
{
aux=T[nod];
T[nod]=rad;
nod=aux;
}
return rad;
}
void Union(int nod1, int nod2)
{
T[nod2]=nod1;
}
int main()
{
in>>n>>m;
for (int i=1; i<=m; i++)
{
in>>op>>x>>y;
if (op==1)
{
int a=Find(x),b=Find(y);
if (a!=b) Union(a, b);
}
else
{
if (Find(x)==Find(y)) out<<"DA"<<'\n';
else out<<"NU"<<'\n';
}
}
}