Cod sursa(job #2755499)

Utilizator eduardpetcuPetcu Eduard Gabriel eduardpetcu Data 27 mai 2021 15:43:47
Problema Paduri de multimi disjuncte Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int L[100005],c,x,y,n,m,a;
int main()
{f>>n>>m;
for(int i=1;i<=n;i++)
    L[i]=i;
for(int i=1;i<=m;i++)
{
    f>>c>>x>>y;
   if(c==1)
   {
   a=L[y];
   for(int j=1;j<=n;j++)
    if(L[j]==a)L[j]=L[x];
   }
     if(c==2)
    {
        if(L[x]==L[y])
            g<<"DA"<<endl;
        else g<<"NU"<<endl;
    }

}

    return 0;
}