Pagini recente » Cod sursa (job #1728165) | Cod sursa (job #1930831) | Cod sursa (job #1557799) | Cod sursa (job #1777430) | Cod sursa (job #2029462)
#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;
x = Find(x);
y = Find(y);
if (op == 1)
{
if (x != y) Union(x,y);
}
else
{
if (x != y) fout << "NU\n";
else fout << "DA\n";
}
}
}
int main()
{
Citire();
fin.close();
fout.close();
return 0;
}