Cod sursa(job #2142341)
| Utilizator | Data | 24 februarie 2018 22:33:29 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.69 kb |
#include <fstream>
using namespace std;
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
int t[100001];
int root(int x)
{
int y = x, next;
while(t[y])
{
y = t[y];
}
while(t[x])
{
next = t[x];
t[x] = y;
x = next;
}
return y;
}
int main()
{
int n, m, cod, x, y;
scanf("%d %d", &n, &m);
while(m--)
{
scanf("%d %d %d", &cod, &x, &y);
if(cod & 1)
{
t[root(x)] = root(y);
}
else
{
if (root(x) ^ root(y)) fout << "NU\n";
else fout << "DA\n";
}
}
}
