Pagini recente » Cod sursa (job #2343163) | Rating busuioc Flavius (busuioc21) | Cod sursa (job #2656947) | Cod sursa (job #3147874) | Cod sursa (job #2037904)
#include <bits/stdc++.h>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int parinti[100001];
int root(int n){
while (parinti[n]!=0)
n = parinti[n];
return n;
}
void q1(int n1, int n2){
parinti[root(n2)] = root(n1);
}
void q2(int n1, int n2){
if (root(n1) == root(n2))
out << "DA\n";
else
out << "NU\n";
}
int main(){
int n, m, i, t, n1, n2;
in >> n >> m;
for (i=1; i<=m; i++){
in >> t >> n1 >> n2;
if (t == 1)
q1(n1, n2);
else
q2(n1, n2);
}
}