Pagini recente » Cod sursa (job #268648) | Cod sursa (job #2196520) | Cod sursa (job #3193987) | Cod sursa (job #2009338) | Cod sursa (job #2106949)
#include <iostream>
#include <fstream>
#define MAX 100001
using namespace std;
int n,m,cod,p[MAX],a,b;
int findr(int nd){
if(nd!=p[nd])p[nd]=findr(p[nd]);
return p[nd];
}
int main()
{
ifstream f ("disjoint.in");
ofstream g ("disjoint.out");
f>>n>>m;
for(int i=1;i<=n;i++)p[i]=i;
for(int i=1;i<=m;i++){
f>>cod>>a>>b;
if(cod==1)p[findr(a)]=findr(b);
else {
a=findr(a);b=findr(b);
if(a==b)g<<"DA\n";
else g<<"NU\n";
}
}
f.close();
g.close();
return 0;
}