Pagini recente » Cod sursa (job #2589754) | Cod sursa (job #817734) | Cod sursa (job #78332) | Borderou de evaluare (job #156724) | Cod sursa (job #1801790)
#include<bits/stdc++.h>
using namespace std;
int Array[100100],count,number,operation,t,x,y;
int find(int nod){
if (Array[nod] == nod) return nod;
int help = find(Array[nod]);
Array[nod] = help;
return help;
}
void unite(int a, int b){
a=find(a);
b=find(b);
Array[a]=b;
}
int main(){
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
ios_base::sync_with_stdio(false);
fin.tie(0);
fin>>number>>operation;
for(long count=1;count<=number;count++) Array[count]=count;
for(long count=1;count<=operation;count++){
fin >> t >>x >>y;
if (t==1) unite(x,y);
else fout<<(find(x)==find(y)?"DA":"NU")<<endl;
}
return 0;
}