Pagini recente » Cod sursa (job #2752884) | Cod sursa (job #1594244) | Cod sursa (job #1071566) | Cod sursa (job #953883) | Cod sursa (job #2279992)
#include <bits/stdc++.h>
#define dm 100005
std :: ifstream fin("disjoint.in");
std :: ofstream fout("disjoint.out");
using namespace std;
int v[dm], n, m;
int root(int x)
{
if(v[x] != x)
return root(v[x]);
else
return x;
}
struct operatii{
int type;
int x;
int y;
}query[dm];
int main()
{
int x, y, type;
fin >> n >> m;
for(int i = 1; i <= n; i++)
v[i] = i;
for(int i = 1; i <= m; i++)
fin >> query[i].type >> query[i].x >> query[i].y;
for(int i = 1; i <= m; i++)
{
if(query[i].type == 1)
v[query[i].y] = root(query[i].x);
else if(query[i].type == 2)
{
if(root(query[i].x) == root(query[i].y))
{
fout << "DA" << "\n";
}
else fout << "NU" << "\n";
}
}
return 0;
}