Pagini recente » Cod sursa (job #2037740) | Cod sursa (job #2486404) | Cod sursa (job #2825546) | Cod sursa (job #441114) | Cod sursa (job #2106936)
#include <iostream>
#include <fstream>
#define MAX 100001
using namespace std;
int n,m,cod,p[MAX],a,b;
int findr(int nd){
while(nd!=p[nd])nd=p[nd];
return 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 {
if(findr(a)==findr(b))g<<"DA\n";
else g<<"NU\n";
}
}
f.close();
g.close();
return 0;
}