Pagini recente » Borderou de evaluare (job #1115475) | Borderou de evaluare (job #1650571) | Cod sursa (job #1197823) | Borderou de evaluare (job #1380143) | Cod sursa (job #2942410)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int n, m;
vector < int > t;
int gasesteTata( int n )
{
if( t[n] == 0 )
return n;
t[n] = gasesteTata( t[n] );
return t[n];
}
int main()
{
ifstream f("disjoint.in");
ofstream g("disjoint.out");
f >> n >> m;
t = vector < int > ( n + 1, 0 );
for( int i = 0; i < m; ++i )
{
int op, x, y;
f >> op >> x >> y;
if( op == 1 )
{
int tx = gasesteTata( x ), ty = gasesteTata( y );
t[ty] = tx;
}
else
g << ( ( gasesteTata( x ) == gasesteTata( y ) ) ? "DA\n" : "NU\n" );
}
f.close();
g.close();
return 0;
}