Pagini recente » Cod sursa (job #1264015) | Cod sursa (job #238897) | Cod sursa (job #1889719) | Cod sursa (job #2396305) | Cod sursa (job #2377929)
#include <bits/stdc++.h>
using namespace std;
int p[100001], n, m;
int find(int x)
{
if (p[x] == x)
return x;
else
return p[x] = find(p[x]);
}
void unite(int x, int y)
{
int a = find(x);
int b = find(y);
p[b] = a;
}
int main()
{
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
cin >> n >> m;
for (int i = 1; i <= n; i++)
p[i] = i;
for (int i = 1; i <= m; i++)
{
int c, x, y;
cin >> c >> x >> y;
if (c == 1)
unite(x, y);
else if(find(x) == find(y))
cout << "DA\n";
else
cout << "NU\n";
}
return 0;
}