Pagini recente » Cod sursa (job #2489164) | Cod sursa (job #1925464) | Cod sursa (job #2759856) | Cod sursa (job #2798030) | Cod sursa (job #868627)
Cod sursa(job #868627)
#include <fstream>
#include <iostream>
using namespace std;
int main() {
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m;
int *p;
fin>>n>>m;
p = new int[n+1];
for(int i=1; i<=n; i++) p[i]=i;
for(int i=1; i<=m; i++) {
int t,x,y;
fin>>t>>x>>y;
if(t==1) {
int a = p[y];
while(a != p[a]) {
//p[a] = x;
a = p[a];
}
p[a]=x;
for(int i=1; i<=n; i++) if(p[i]==a) p[i]=x;
} else {
int a, b;
if(p[x]==p[y]) fout<<"DA"<<endl; else fout<<"NU"<<endl;
}
}
return 0;
}