Pagini recente » Cod sursa (job #1163544) | Cod sursa (job #1929376) | Cod sursa (job #1575082) | Cod sursa (job #1573095) | Cod sursa (job #2142348)
#include <fstream>
#include <cstdio>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
//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";
}
}
}