Cod sursa(job #2277628)
| Utilizator | Data | 6 noiembrie 2018 17:41:39 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 40 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 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)
{ int aux = a[x] ;
for( j = 1 ; j <= m ; j ++ )
if( a[j] == aux )
a[j] = a[y] ;
}
}
}
