Pagini recente » Cod sursa (job #2695557) | Cod sursa (job #3326254) | Borderou de evaluare (job #3341974) | Cod sursa (job #1677557) | Cod sursa (job #3312916)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int v[100001];
int Find(int k)
{
if(v[k]==0)
return k;
else
{
int x=Find(v[k]);
v[k]=x;
return x;
}
}
void unire(int x, int y)
{
v[y]=x;
}
int main()
{
int n, m, t, x, y;
cin >> n >> m;
while(m--)
{
cin >> t >> x >> y;
if(t==1)
{
unire(Find(x), Find(y));
}
else
{
if(Find(x)==Find(y))
cout << "DA\n";
else
cout << "NU\n";
}
}
return 0;
}