Pagini recente » Cod sursa (job #2587075) | Cod sursa (job #717612) | Cod sursa (job #2880768) | Cod sursa (job #2307718) | Cod sursa (job #2304039)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, t[100001], m, x, y, a, b, cod, i;
int rad(int nod){
int sol = nod;
while(t[sol] > 0)
sol = t[sol];
while(t[nod] > 0){
int a = t[nod];
t[nod] = sol;
nod = a;
}
return sol;
}
int main(){
fin>>n>>m;
for(i=1;i<=n;i++)
t[i] = -1;
while(m--){
fin>>cod>>x>>y;
a = rad(x);
b = rad(y);
if(cod == 1 && a != b){
t[b] += t[a];
t[a] = b;
}
if(cod == 2){
if(a == b)
fout<<"DA\n";
else
fout<<"NU\n";
}
}
return 0;
}