Pagini recente » Cod sursa (job #2915650) | Cod sursa (job #1151783) | Cod sursa (job #2727713) | Cod sursa (job #2950035) | Cod sursa (job #2320835)
#include <fstream>
#define input "disjoint.in"
#define output "disjoint.out"
#define MULT_MAX 100005
using namespace std;
ifstream in(input);
ofstream out(output);
int father[MULT_MAX], multimi, operatii;
int Get_Father(int nod)
{
if(father[nod] == nod) return nod;
father[nod] = Get_Father(father[nod]);
return father[nod];
}
void Reunion(int a, int b)
{
father[Get_Father(a)] = Get_Father(b);
}
void Read_Data()
{
in >> multimi >> operatii;
for(int i = 1; i <= multimi; i++)
father[i] = i;
for(int i = 1; i <= operatii; i++)
{
int task, a, b;
in >> task >> a >> b;
if(task == 1) Reunion(a, b);
if(task == 2)
{
if(Get_Father(a) == Get_Father(b))
out << "DA\n";
else
out << "NU\n";
}
}
}
int main()
{
Read_Data();
return 0;
}