Pagini recente » Cod sursa (job #2833885) | Cod sursa (job #1322266) | Cod sursa (job #2946513) | Cod sursa (job #267296) | Cod sursa (job #1809190)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int NMax = 100005;
int N,M,TT[NMax];
int Root(int x)
{
while(x != TT[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;
}