Pagini recente » Cod sursa (job #2962717) | Cod sursa (job #574997) | Cod sursa (job #1613708) | Cod sursa (job #2962790) | Cod sursa (job #2289056)
//
// main.cpp
// Disjoint
//
// Created by Darius Buhai on 24/11/2018.
// Copyright © 2018 Darius Buhai. All rights reserved.
//
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n,m;
int a[100001];
bool is_dad(int c, int d)
{
while(a[c]){
if(c==d)
return true;
c = a[c];
}
if(c==d)
return true;
return false;
}
int main() {
fin>>n>>m;
for(int i=0;i<m;i++)
{
int action, x, y;
fin>>action>>x>>y;
if(action==1)
a[x] = y;
else{
if(is_dad(x, y) || is_dad(y,x))
fout<<"DA"<<endl;
else
fout<<"NU"<<endl;
}
}
return 0;
}