Pagini recente » Cod sursa (job #280798) | Cod sursa (job #360614) | Cod sursa (job #1501622) | Cod sursa (job #944318) | Cod sursa (job #1548221)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int NMax = 100005;
int N,M;
int T[NMax];
int Father(int Nod)
{
while(Nod!=T[Nod])
Nod = T[Nod];
return Nod;
}
void Unite(int x, int y)
{
T[x] = y;
}
int main()
{
fin>>N>>M;
for(int i = 1; i<=N; i++)
T[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;
}