Cod sursa(job #2692942)
Utilizator | Nanu Robert-Ionut robertnanu_fmi | Data | 4 ianuarie 2021 13:37:27 |
---|---|---|---|
Problema | Paduri de multimi disjuncte | Scor | 70 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.58 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int nMax = 1e5 + 5;
int n, m, x, y, a, b, v[nMax], rad, cod;
int radacina(int x)
{
while(v[x] != 0)
x = v[x];
return x;
}
int main()
{
f >> n >> m;
while(m--)
{
f >> cod >> x >> y;
if(cod == 1)
v[radacina(x)] = radacina(y);
if(cod == 2)
if(radacina(x) == radacina(y))
g << "DA\n";
else
g << "NU\n";
}
return 0;
}