Pagini recente » Cod sursa (job #1783297) | Cod sursa (job #2939132) | Cod sursa (job #50547) | Cod sursa (job #650345) | Cod sursa (job #2864375)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m;
int t[100005];
void Union(int x, int y)
{
t[y] = x;
}
int Find(int x)
{
int rad = x, y;
while(t[rad] != 0)
rad = t[rad];
while(x != rad)
{
y = t[x];
t[x] = rad;
x = y;
}
return rad;
}
void Solve()
{
int i, op, x, y;
fin >> n >> m;
for(i = 1;i <= m;i++)
{
fin >> op >> x >> y;
x = Find(x);
y = Find(y);
if(op == 1)
Union(x, y);
else
{
if(x == y)
fout << "DA\n";
else
fout << "NU\n";
}
}
}
int main()
{
Solve();
return 0;
}