Pagini recente » Cod sursa (job #3139270) | Cod sursa (job #1950339) | Borderou de evaluare (job #2100979) | Cod sursa (job #425282) | Cod sursa (job #826142)
Cod sursa(job #826142)
# 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 ;
}