Cod sursa(job #2277607)

Utilizator tetrismeila ana gabriela tetris Data 6 noiembrie 2018 16:53:53
Problema Paduri de multimi disjuncte Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("disjoint.in") ;
ofstream g("disjoint.out") ;
int m , n , i , j , a[100001];
int main()
{

f >> m >> n ;
for( i =1 ; i <= m ; i ++ ){
    a[i] = i ;
}
for( i = 1 ; i <= n ; i ++ )
{  int cod , x , y ;
    f >> cod >> x >> y ;
    if( cod == 2 )
        if( a[x] == a[y] )
             g << "DA" << "\n" ;
        else
            g << "NU" << "\n" ;
    if( cod == 1)
    {
        for( j = 1 ; j <= m ; j ++ )
            if( a[j] == a[x] )
            a[j] = a[y] ;
    }
}

}