Pagini recente » Cod sursa (job #486319) | Cod sursa (job #1088877) | Cod sursa (job #2147608) | Cod sursa (job #1875690) | Cod sursa (job #2692927)
#include<bits/stdc++.h>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int nMax = 1e5 + 5;
int n, m, x, y, a, b, v[nMax], rad, cod;
int radacina(int x)
{
while(v[x]!=0)
x=v[x];
return x;
}
int main()
{
f >> n >> m;
for(int i = 1; i <= m; ++i)
{
f >> cod;
f >> x >> y;
if(cod == 1)
v[x] = y;
if(cod == 2)
{
a = radacina(x);
b = radacina(y);
if(a == 0 and b == 0)
g << "NU" << "\n";
else
{
if(a == b)
g << "DA" << "\n";
else
g << "NU" << "\n";
}
}
}
return 0;
}