Cod sursa(job #826142)

Utilizator toniobFMI - Barbalau Antonio toniob Data 30 noiembrie 2012 09:16:03
Problema Paduri de multimi disjuncte Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
# include <fstream>

using namespace std ;


ifstream in ( "disjoint.in" ) ;
ofstream out ( "disjoint.out" ) ;


const int M = 100001 ;
int n , m , tata [ M ] ;


int vf ( int nod ) {

    if ( ! tata [ nod ] ) {
        return nod ;
    }

    int vftata = vf ( tata [ nod ] ) ;
    tata [ nod ] = vftata ;

    return vftata ;

}

void executa ( int op , int x , int y ) {

    int vfx = vf ( x ) , vfy = vf ( y ) ;

    if ( op == 1 ) {
        tata [ vfx ] = vfy ;

        return ;
    }

    out << ( vfx == vfy ? "DA\n" : "NU\n" ) ;

}

void citire (  ) {

    in >> n >> m ;
    for ( int i = 1 , op , x , y ; i <= m ; ++ i ) {
        in >> op >> x >> y ;
        executa ( op , x , y ) ;
    }

}

int main () {

    citire (  ) ;

    return 0 ;

}