Cod sursa(job #2535173)
Utilizator | Marco Vraja ArkhamKnighty | Data | 31 ianuarie 2020 16:47:52 |
---|---|---|---|
Problema | Paduri de multimi disjuncte | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.66 kb |
#include <fstream>
using namespace std;
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int v[100001], n, m;
void citire()
{
cin >> n >> m;
for(int i = 1 ; i <= n ; i++)
v[i] = i;
}
void rez()
{
int t, x, y, aux;
for(int i = 1 ; i <= m ; i++)
{
cin >> t >> x >> y;
while(x != v[x]) aux = v[v[x]], v[x] = aux, x = aux;
while(y != v[y]) aux = v[v[y]], v[y] = aux, y = aux;
if(t == 1) v[x] = y;
else
(x == y) ?
cout << "DA \n" : cout << "NU \n";
}
}
int main()
{
citire();
rez();
return 0;
}