Pagini recente » Cod sursa (job #3215051) | Cod sursa (job #2904744) | Cod sursa (job #604808) | Cod sursa (job #2025837) | Cod sursa (job #1581748)
#include <cstdio>
#include <fstream>
#define NMax 1000053
using namespace std;
int root[NMax];
int x,y,n,m,p;
int main()
{
ifstream f("disjoint.in");
ofstream g("disjoint.out");
f >> n >> m;
for(int i = 1; i <= m; ++i){
f >> p >> x >> y;
int w = y;
while(root[w] != 0)
w = root[w];
int t = x;
while(root[t] != 0)
t = root[t];
if(p == 1){
root[t] = w;
}else{
if(t != w){
g << "NU" <<"\n";
}else
g << "DA" <<"\n";
}
}
return 0;
}