Pagini recente » Cod sursa (job #1289712) | Cod sursa (job #458425) | Cod sursa (job #1207758) | Cod sursa (job #825347) | Cod sursa (job #2306930)
#include <bits/stdc++.h>
#define N 100001
#define ll long long
#define f first
#define s second
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int a[N], g[N];
int top(int i){
if(a[i]!=i)
a[i]=top(a[i]);
return a[i];
}
int main(){
int n,m,i,x,y,t,g1,g2;
in>>n>>m;
for(i=1; i<=n; ++i)
a[i]=i;
while(m--){
in>>t>>x>>y;
if(t==1){
g1=top(x), g2=top(y);
if(g[g1]>g[g2])
a[y]=x;
else if(g[g1]<g[g2])
a[x]=y;
else
a[y]=x, ++g[x];
}
else{
if(a[top(x)]==a[top(y)]) out<<"DA\n";
else out<<"NU\n";
}
}
return 0;
}