Pagini recente » Cod sursa (job #2665089) | Cod sursa (job #838751) | Cod sursa (job #1805120) | Cod sursa (job #1381815) | Cod sursa (job #3030619)
#include <fstream>
#include <vector>
#include <queue>
#include <bitset>
using namespace std;
string file = "disjoint";
ifstream cin (file + ".in");
ofstream cout (file + ".out");
const int N = 100000;
int t[N+1];
int radacina (int x)
{
if (t[x] == 0)
{
return x;
}
t[x] = radacina(t[x]);
return t[x];
}
int main()
{
int n,m,op,x,y;
cin >> n >> m;
for (int i=1; i<=m; i++)
{
cin >> op >> x >> y;
if (op == 1)
{
t[y] = x;
}
else
{
int rx = radacina(x);
int ry = radacina(y);
cout << (rx == ry ? "DA" : "NU") << '\n';
}
}
}