Pagini recente » Cod sursa (job #3217634) | Cod sursa (job #2139123) | Cod sursa (job #2730623) | Cod sursa (job #65426) | Cod sursa (job #2820252)
#include <fstream>
#include <climits>
#define ll long long
using namespace std;
const int NMAX = 503;
int t[NMAX];
int root(int x)
{
if (!t[x])
return x;
t[x] = root(t[x]);
return t[x];
}
void joint(int x, int y)
{
t[y] = root(x);
}
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int main()
{
int n, m;
cin >> n >> m;
while (m--)
{
int op, x, y;
cin >> op >> x >> y;
if (op == 1)
joint(x, y);
else
{
int v1 = root(x);
int v2 = root(y);
if (v1 == v2)
cout << "DA";
else
cout << "NU";
cout << "\n";
}
}
}