Pagini recente » Cod sursa (job #2680845) | Cod sursa (job #1913544) | Cod sursa (job #2874865)
#include <bits/stdc++.h>
using namespace std;
ifstream in ("disjoint.in");
ofstream out ("disjoint.out");
int n,m,T[501],op,x,y;
int Find(int nod)
{
while (T[nod]!=0)
{
nod=T[nod];
}
return nod;
}
void Union(int nod1, int nod2)
{
T[nod2]=nod1;
}
int main()
{
cin>>n>>m;
for (int i=1; i<=m; i++)
{
cin>>op>>x>>y;
if (op==1)
{
if (Find(x)!=Find(y)) Union(x, y);
}
else
{
if (Find(x)==Find(y)) cout<<"DA"<<'\n';
else cout<<"NU"<<'\n';
}
}
}