Pagini recente » winter2020 | Cod sursa (job #2589209) | Cod sursa (job #1615267) | Cod sursa (job #2773972) | Cod sursa (job #1913266)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int nMax = 100005;
int t[nMax];
int n, m;
inline int Find(int x)
{
int rad, y;
rad = x;
while(t[rad] != 0)
rad = t[rad];
while(t[x])
{
y = t[x];
t[x] = rad;
x = y;
}
return rad;
}
inline void Union(int x, int y)
{
t[y] = x;
}
inline 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;
}