Mai intai trebuie sa te autentifici.
Cod sursa(job #2173895)
| Utilizator | Data | 16 martie 2018 09:27:33 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 70 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.68 kb |
#include <fstream>
#define nmax 100001
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int n, m, i, j, c, x, y, tata[nmax], fx, fy;
int f (int x)
{
if (tata[x] == x)
return x;
return x = f (tata[x]);
}
int main()
{
fin >> n >> m;
for (i = 1; i <= n; i++)
tata[i] = i;
for (i = 1; i <= m; i++)
{
fin >> c >> x >> y;
fx = f (x);
fy = f (y);
if (c == 1)
{
tata[fx] = fy;
}
else
{
if (fx == fy)
fout << "DA\n";
else fout << "NU\n";
}
}
return 0;
}
