Pagini recente » Cod sursa (job #1073752) | Cod sursa (job #195877) | Cod sursa (job #1279179) | Cod sursa (job #165710) | Cod sursa (job #1786690)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m, disjoint[100001];
int father(int x)
{
while(disjoint[x])
x = disjoint[x];
return x;
}
void unify(int x, int y)
{
x = father(x);
y = father(y);
disjoint[y] = x;
}
int main()
{
fin >> n >> m;
for(int i = 1; i <= m; ++i)
{
int op, x, y;
fin >> op >> x >> y;
if(op == 1)
{
unify(x, y);
}
else
{
if(father(x) == father(y))
{
fout<<"DA\n";
}
else
{
fout<<"NU\n";
}
}
}
return 0;
}