Pagini recente » Cod sursa (job #1074367) | Cod sursa (job #1005447) | Cod sursa (job #2933201) | Cod sursa (job #2152728) | Cod sursa (job #2293075)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("disjoint.in") ;
ofstream g("disjoint.out") ;
int m , n , i , j , a[100001];
int grad( int b )
{
if( a[b] == b )
return b ;
else grad( a[b] ) ;
}
void uneste( int x , int y )
{
if( a[y] == y )
{
a[y] = x ;
return ;
}
int aux = a[y] ;
a[y] = x ;
uneste( x , aux ) ;
}
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 == 1){
uneste ( a[grad( x )] , y ) ;
}
else
if( grad( x ) == grad( y ) )
g << "DA" << "\n" ;
else g << "NU" << "\n" ;
}
return 0;
}