Pagini recente » Rating Gerard (Gerard) | Cod sursa (job #1255869) | Cod sursa (job #1172115) | Monitorul de evaluare | Cod sursa (job #1243643)
#include <fstream>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int t[100001];
int radacina( int x )
{
if ( t[x] == 0 )
return x;
t[x] = radacina(t[x]);
return t[x];
}
void mfind( int x, int y )
{
if ( radacina(x) == radacina(y) )
out << "DA"<<'\n';
else out << "NU"<<'\n';
}
void munion( int x, int y)
{
int rx, ry;
rx = radacina(x);
ry = radacina(y);
t[rx] = ry;
}
int main()
{
int n, m, i, cod, x, y;
in >> n >> m;
for ( i = 1; i <= m; i++ )
{
in >> cod >> x >> y;
if ( cod == 1 )
munion( x, y);
if ( cod == 2 )
mfind( x, y);
}
return 0;
}