Pagini recente » Cod sursa (job #392174) | Cod sursa (job #2454691) | Cod sursa (job #102467) | Cod sursa (job #1196348) | Cod sursa (job #861249)
Cod sursa(job #861249)
#include<fstream>
using namespace std;
const int LIM = 100005;
int p[LIM];
int findParent(int x){
if(p[x]==x)
return x;
else{
p[x]=findParent(p[x]);
return p[x];
}
}
int main(){
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int n,m;
in>>n>>m;
for(int i=1; i<=n; i++)
p[i]=i;
int type, x, y;
for(int i=1; i<=m; i++){
in>>type>>x>>y;
if(type==1){
p[y]=findParent(x);
}
else{
p[y]=findParent(y);
p[x]=findParent(x);
if(p[x]==p[y])
out<<"DA\n";
else out<<"NU\n";
}
}
return 0;
}