Pagini recente » Cod sursa (job #1224779) | Cod sursa (job #1789627) | Rating Iordachioaiei Alex (AlexInfo) | Cod sursa (job #1414080) | Cod sursa (job #861269)
Cod sursa(job #861269)
#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(y);
p[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;
}