Pagini recente » Cod sursa (job #2717476) | Cod sursa (job #1460759) | Cod sursa (job #1206317) | Cod sursa (job #1397207) | Cod sursa (job #2812813)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int v[100005];
int N, M;
int cauta_reprez(int elem)
{
if (elem == v[elem]){
return elem;
}
v[elem] = cauta_reprez(v[elem]);
return v[elem];
}
void unire_triburi(int om1, int om2)
{
int reprez_om1 = cauta_reprez(om1);
int reprez_om2 = cauta_reprez(om2);
v[reprez_om1] = reprez_om2;
}
int main()
{
fin >> N >> M;
for (int i = 1; i <= N; i++) v[i] = i;
int tip, x, y;
while (M){
--M;
fin >> tip >> x >> y;
if (tip == 1){
unire_triburi(x, y);
}
else{
if (cauta_reprez(x) == cauta_reprez(y)){
fout << "DA" << '\n';
}
else fout << "NU" << '\n';
}
}
return 0;
}