Pagini recente » Cod sursa (job #3288481) | Statisticile problemei Camere | Cod sursa (job #2654736) | Cod sursa (job #932396) | Cod sursa (job #3285317)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int t[100003], n, m;
void Union(int x, int y)
{
t[x] = y;
}
int Find(int x)
{
if (t[x] == 0) return x;
return t[x] = Find(t[x]);
}
int main()
{
int i, op, x, y;
fin >> n >> m;
for (i = 1; i <= m; i++)
{
fin >> op >> x >> y;
x = Find(x);
y = Find(y);
if (op == 1 && x != y) Union(x, y);
else if (op == 2)
{
if (x != y) fout << "NU\n";
else fout << "DA\n";
}
}
return 0;
}
//0, 1, 3-5, 7-18, 21, 22, 24-27, 29, 30, 34-36, 42, 44, 45, 47, 48, 51, 54, 56-58