Pagini recente » Cod sursa (job #2192203) | Cod sursa (job #2937667) | Cod sursa (job #979646) | Cod sursa (job #666328) | Cod sursa (job #639421)
Cod sursa(job #639421)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int MAXN = 100005;
int TT[MAXN] , N , M;
inline int find(const int &x)
{
int R;
for(R = x;TT[R] != R;R = TT[R]);
return R;
}
void unite(const int &x,const int &y)
{
TT[x] = y;
}
int main()
{
fin>>N>>M;
for(int i=1;i<=N;++i)
TT[i] = i;
for(;M;M--)
{
int x , y , tip;
fin>>tip>>x>>y;
if(tip==1) unite(find(x),find(y));
else
if(find(x)==find(y))
fout<<"DA\n";
else
fout<<"NU\n";
}
return 0;
}