Pagini recente » Cod sursa (job #3274213) | Borderou de evaluare (job #2471248) | Profil The_Viper_The_Mountain_And_The_Imp | Borderou de evaluare (job #2123349) | Cod sursa (job #2062572)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int NMax = 100000;
int TT[NMax + 5];
int N,M;
int Root(int x)
{
while(TT[x] != x)
x = TT[x];
return x;
}
void Unite(int x, int y)
{
TT[x] = y;
}
int main()
{
fin >> N >> M;
for(int i = 1; i <= N; ++i)
TT[i] = i;
while(M--)
{
int op,x,y;
fin >> op >> x >> y;
if(op == 1)
Unite(Root(x),Root(y));
if(op == 2)
if(Root(x) == Root(y))
fout << "DA\n";
else
fout << "NU\n";
}
return 0;
}