Pagini recente » Cod sursa (job #3139046) | Cod sursa (job #2907562) | Cod sursa (job #247596) | Cod sursa (job #523123) | Cod sursa (job #1783997)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int NMax = 100005;
int N,M;
int TT[NMax];
int Father(int Nod)
{
while(Nod != TT[Nod])
Nod = TT[Nod];
return Nod;
}
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(Father(x),Father(y));
if(op == 2)
{
if(Father(x) == Father(y))
fout<<"DA\n";
else
fout<<"NU\n";
}
}
return 0;
}