Pagini recente » Cod sursa (job #2804889) | Cod sursa (job #893040) | Imbunatatire teste | Cod sursa (job #370957) | Cod sursa (job #2108876)
#include <iostream>
#include <vector>
#include <queue>
#include <fstream>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
const int MAX = 100005;
int T[MAX];
int N ,M ,tip, x, y;
void Unifica(int x ,int y)
{
T[y] = x;
}
int Radacina(int nod)
{
int neXT;
int R = nod;
while(T[R] != R) R= T[R];
return R;
}
int main()
{
in >> N >> M;
for ( int i = 1; i <= N ; ++i)
{
T[i] = i;
}
for ( int i = 1; i <= M ;++i)
{
in >> tip >> x >> y;
if ( tip == 1)
if ( Radacina(x) != Radacina(y) )Unifica(Radacina(x),Radacina(y));
if ( tip == 2)
if ( Radacina(x) != Radacina(y) ) out << "NU" <<"\n";
else out << "DA" <<"\n";
}
return 0;
}