Pagini recente » Cod sursa (job #2603712) | Cod sursa (job #1029813) | Cod sursa (job #42710) | Cod sursa (job #1024262) | Cod sursa (job #2573126)
#include <fstream>
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int N, M, i, cer, x, y, t1, t2, t[ 100005 ];
void cautare( int nod, int &tp )
{
if ( t[ nod ] != 0 )
{
cautare( t[ nod ], tp );
t[ nod ] = tp;
}
else
{
tp = nod;
}
}
int main()
{
fin >> N >> M;
for ( i = 1; i <= M; i++ )
{
fin>> cer >> x >> y;
cautare( x, t1 );
cautare( y, t2 );
if ( cer == 1 )
{
t[ t2 ] = t1;
}
else if ( cer == 2 )
{
if ( t1 == t2 )
fout<< "DA" << '\n';
else
fout<< "NU" << '\n';
}
}
}