Pagini recente » Cod sursa (job #533655) | Cod sursa (job #2314841) | Cod sursa (job #2665054) | Cod sursa (job #2300391) | Cod sursa (job #2571647)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int Nmax = 1e5 + 5;
int n, m;
int t[Nmax];
void Union(int x, int y)
{
t[y] = x;
}
int Find(int x)
{
int y, rad = x;
while(t[rad])
rad = t[rad];
while(x != rad)
{
y = t[x];
t[x] = rad;
x = y;
}
return rad;
}
int main()
{
fin >> n >> m;
int cod, x, y;
for(int i = 1; i <= m; i++)
{
fin >> cod >> x >> y;
y = Find(y);
x = Find(x);
if(cod == 1)
{
if(x != y)
Union(x, y);
}
else
{
if(x != y) fout << "NU\n";
else fout << "DA\n";
}
}
fin.close();
fout.close();
return 0;
}