Pagini recente » Cod sursa (job #2350455) | Cod sursa (job #2493638) | Cod sursa (job #3175708) | Cod sursa (job #2598625) | Cod sursa (job #2874871)
#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)
{
while (T[nod]!=0)
{
nod=T[nod];
}
return nod;
}
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';
}
}
}