Pagini recente » Cod sursa (job #2319793) | Cod sursa (job #2859442) | Cod sursa (job #3285503) | Cod sursa (job #3230760) | Cod sursa (job #1646333)
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#define NMax 100005
#define mod 1999999973
#define INF 0x3f3f3f3f
using namespace std;
int n,m,p,x,y,vf1,vf2;
int rang[NMax],rad[NMax];
int root(int k){
while(rad[k])
k = rad[k];
return k;
}
int main()
{
freopen("disjoint.in","r",stdin);
freopen("disjoint.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i = 1; i <= m; ++i){
scanf("%d%d%d",&p,&x,&y);
vf1 = root(x);
vf2 = root(y);
if(p == 1){
rad[vf2] = vf1;
}else{
if(vf1 == vf2)
printf("DA\n");
else
printf("NU\n");
}
}
return 0;
}