Cod sursa(job #2553053)

Utilizator ionita786Ionita Daniel ionita786 Data 21 februarie 2020 15:55:57
Problema Paduri de multimi disjuncte Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
const int Nmax = 100001;
vector <int> t(Nmax);
int q,n,m,x,y;
void update()
{
    for(int i = 1; i <= n; ++i)
        if(t[i] == y) t[i] = x;
}
int main()
{

    in >> n >> m;
    while(m--)
    {
        in >> q >> x >> y;
        if(q == 1)
        {
            if(!t[x])
                t[x] = x;
            if(!t[y])
                t[y] = x;
            update();
        }
        else
        {
            if(t[x] == t[y])
                out << "DA" << '\n';
            else
                out << "NU" << '\n';
        }
    }
    return 0;
}