Cod sursa(job #2837330)
| Utilizator | Data | 22 ianuarie 2022 09:50:26 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.72 kb |
#include <fstream>
#define NMAX 100005
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int n, m, type, x, y;
int papa[NMAX];
int main()
{
in >> n >> m;
while (m)
{
in >> type >> x >> y;
switch(type)
{
case 1:
while (papa[x]) x = papa[x];
papa[y] = x;
break;
case 2:
while (papa[x]) x = papa[x];
while (papa[y]) y = papa[y];
if (x == y)
out << "DA" << '\n';
else
out << "NU" << '\n';
break;
}
--m;
}
return 0;
}
