Pagini recente » Borderou de evaluare (job #1712612) | Cod sursa (job #3133605) | Cod sursa (job #2289106)
//
// main.cpp
// Disjoint
//
// Created by Darius Buhai on 24/11/2018.
// Copyright © 2018 Darius Buhai. All rights reserved.
//
#include <iostream>
#include <fstream>
#define MAXL 100001
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n,m;
int a[MAXL];
int dad(int c)
{
while(a[c]) c = a[c];
return c;
}
int main() {
fin>>n>>m;
for(int i=0;i<m;i++)
{
int action, x, y;
fin>>action>>x>>y;
if(action==1)
a[y] = x;
else{
if(dad(x)==dad(y))
fout<<"DA"<<endl;
else
fout<<"NU"<<endl;
}
}
return 0;
}