Pagini recente » Cod sursa (job #2772413) | Cod sursa (job #984463) | Cod sursa (job #328908) | Cod sursa (job #1012499) | Cod sursa (job #1795198)
#include <fstream>
#define VAL 100005
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int N, M, i;
int t, x, y;
int dx, dy;
int fat[VAL];
int GetFat(int a)
{
if (fat[a]!=a)
fat[a]=GetFat(fat[a]);
return fat[a];
}
int main()
{
fin >> N >> M;
for (i=1; i<=N; i++)
fat[i]=i;
for (i=1; i<=M; i++)
{
fin >> t >> x >> y;
dx=GetFat(x);
dy=GetFat(y);
if (t==1)
fat[x]=dy;
else
{
if (fat[x]==fat[y])
fout << "DA\n";
else
fout << "NU\n";
}
}
fin.close();
fout.close();
return 0;
}