Pagini recente » Cod sursa (job #556984) | Cod sursa (job #2950573) | Cod sursa (job #242316) | Cod sursa (job #2952655) | Cod sursa (job #1350410)
#include <fstream>
#define NMax 100005
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int N,M,TT[NMax];
void Unite(int x, int y)
{
TT[x] = y;
}
int Father(int x)
{
while(TT[x]!=x)
x=TT[x];
return x;
}
int main()
{
fin>>N>>M;
for(int i=1;i<=N;i++)
TT[i] = i;
while(M--)
{
int cod,x,y;
fin>>cod>>x>>y;
if(cod==1)
Unite(Father(x),Father(y));
if(cod==2)
if(Father(x)==Father(y))
fout<<"DA\n";
else
fout<<"NU\n";
}
return 0;
}