Pagini recente » Cod sursa (job #2598648) | Cod sursa (job #2931272) | Cod sursa (job #901770) | Cod sursa (job #2431024) | Cod sursa (job #2262725)
//
// main.cpp
// paduri_de_multimi_disjuncte
//
// Created by Tereza Oprea on 17/10/2018.
// Copyright © 2018 Tereza Oprea. All rights reserved.
//
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int m, n, x, y, c, p[100010];
int gaseste_rep (int nod){
if (p[nod] == nod)
return nod;
p[nod] = gaseste_rep(p[nod]);
return p[nod];
}
int main() {
fin >> n >> m;
for (int i=1; i<=n; i++)
p[i] = i;
for (int i=1; i<=m; i++)
{
fin >> c >> x >> y;
if (c==1)
{
gaseste_rep(x);
gaseste_rep(y);
p[p[x]] = p[y];
}
else
{
gaseste_rep(x);
gaseste_rep(y);
if (p[x] == p[y])
fout << "DA" << '\n';
else
fout << "NU" << '\n';
}
}
return 0;
}