Pagini recente » Cod sursa (job #3228817) | Cod sursa (job #1966169) | Cod sursa (job #1426161) | Cod sursa (job #1447801) | Cod sursa (job #2318915)
#include <fstream>
#define N 100001
#define ll long long
#define f first
#define s second
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("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;
fin>>n>>m;
for(i=1; i<=n; ++i)
a[i]=i;
while(m--){
fin>>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)]) fout<<"DA\n";
else fout<<"NU\n";
}
}
return 0;
}