Pagini recente » Cod sursa (job #1761337) | Cod sursa (job #1035846) | Cod sursa (job #2272392) | Cod sursa (job #1138853) | Cod sursa (job #2029456)
#include <bits/stdc++.h>
#define in "disjoint.in"
#define out "disjoint.out"
using namespace std;
ifstream fin(in);
ofstream fout(out);
int n,m;
int t[100003];
void Union(int x, int y)
{
t[x] = y;
}
int Find(int x)
{
int r,y;
r = x;
while (t[r] != 0)
r = t[r];
///comprimarea drumului
while (x != r)
{
y = t[x];
t[x] = r;
x = y;
}
return r;
}
void Citire()
{
int op,x,y;
fin >> n >> m;
while (m--)
{
fin >> op >> x >> y;
if (op == 1) Union(x,y);
else
{
x = Find(x);
y = Find(y);
if (x != y) fout << "NU\n";
else fout << "DA\n";
}
}
}
int main()
{
Citire();
fin.close();
fout.close();
return 0;
}