Pagini recente » Cod sursa (job #3160966) | Cod sursa (job #768075) | Cod sursa (job #179642) | Cod sursa (job #546920) | Cod sursa (job #3252483)
#include<fstream>
#include<cmath>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int nmax = 100000;
int n,m,tata[nmax];
int find(int nod){
if(tata[nod] == 0)return nod;
else find(tata[nod]);
}
int main(){
fin>>n>>m;
for(int i = 1; i <= m; i++){
int x,y,z;
fin>>z>>x>>y;
if(z == 1){
int a = min(x,y), b = max(x,y);
tata[b] = a;
}
else{
int tx = find(x), ty = find(y);
if(tx == ty)fout<<"DA\n";
else fout<<"NU\n";
}
}
}