Pagini recente » Cod sursa (job #1864340) | Cod sursa (job #867045) | Cod sursa (job #3180564) | Cod sursa (job #950472) | Cod sursa (job #2760493)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m;
int tati[100005];
void Union(int x, int y)
{
tati[y] = x;
}
int Find(int x)
{
int rad, y;
rad = x;
while (tati[rad])
rad = tati[rad];
while (tati[x])
y = tati[x], tati[x] = rad, x = y;
return rad;
}
int main()
{
fin >> n >> m;
for (int i = 1; i <= m; ++i)
{
int cod, x, y;
fin >> cod >> x >> y;
x = Find(x);
y = Find(y);
if (cod == 1)
Union(x, y);
else
{
if (x == y)
fout << "DA\n";
else fout << "NU\n";
}
}
return 0;
}