Pagini recente » Cod sursa (job #2566414) | Cod sursa (job #2950572) | Cod sursa (job #2330649) | Cod sursa (job #25741) | Cod sursa (job #2669564)
#include <iostream>
#include <fstream>
#define O 100005
using namespace std;
int tata[O];
int N, M;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int gasire(int x)
{
if(tata[x] != x)
tata[x] = gasire(tata[x]);
return tata[x];
}
void unire(int a, int b)
{
if(a != b)
if(a < b)
tata[b] = a;
else
tata[a] = b;
}
int main()
{
int x, y, c;
in >> N >> M;
for(int i = 1; i <= N; i++)
tata[i] = i;
for(int i = 1; i <= M; i++)
{
in >> c >> x >> y;
if(c == 1)
unire(x, y);
else
if(gasire(x) == gasire(y))
out << "DA" << '\n';
else
out << "NU" << '\n';
}
}