Pagini recente » Cod sursa (job #3205748) | Cod sursa (job #1242099) | Cod sursa (job #2317802) | Cod sursa (job #802218) | Cod sursa (job #2693185)
#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, v[nMax], cod;
int radacina(int x)
{
while(v[x] != 0)
x = v[x];
return x;
}
int main()
{
f >> n >> m;
while(m--)
{
f >> cod >> x >> y;
if(cod == 1)
v[radacina(y)] = radacina(x);
else
if(radacina(x) == radacina(y))
g << "DA\n";
else
g << "NU\n";
}
return 0;
}