Pagini recente » Cod sursa (job #39486) | Cod sursa (job #1222437) | Cod sursa (job #773793) | Cod sursa (job #3171563) | Cod sursa (job #1621701)
#include <fstream>
#define Nmax 100001
using namespace std;
ifstream f ("disjoint.in");
ofstream g ("disjoint.out");
int n, m, t[ Nmax ];
int multime ( int a )
{
if ( t[ a ] == 0)
return a;
t[ a ] = multime ( t[ a ] );
return t[ a ];
}
void unificare ( int a, int b )
{
int x, y;
x = multime( a );
y = multime( b );
t[ x ] = y;
}
void run ()
{
int x, y, op;
f >> n >> m;
for ( int i = 0; i < m; ++ i )
{
f >> op >> x >> y;
if ( op == 1 )
unificare( x, y );
else
{
if ( multime ( x ) == multime( y ) )
g << "DA" << endl;
else
g << "NU" << endl;
}
}
}
int main()
{
run ();
return 0;
}