Pagini recente » Cod sursa (job #2469163) | Cod sursa (job #819872) | Cod sursa (job #3244674) | Cod sursa (job #2027489) | Cod sursa (job #1846895)
#include <bits/stdc++.h>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int T[100010], n, m, cod, i, x, y;
int compresie(int x)
{
if(T[x] == x) return x;
T[x] = compresie(T[x]);
return T[x];
}
int main()
{
f >> n >> m;
for(i = 1; i <= n; i++)
T[i] = i;
for(; m; m--)
{
f >> cod >> x >> y;
x = compresie(x);
y = compresie(y);
if(cod == 1) T[x] = y;
else x == y ? g << "DA\n" : g << "NU\n";
}
return 0;
}