Pagini recente » Cod sursa (job #100521) | Cod sursa (job #1151869) | Cod sursa (job #432779) | Istoria paginii runda/concurs_freshmen | Cod sursa (job #3030625)
#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)
{
if (x > y)
swap(x,y);
t[y] = x;
}
else
{
int rx = radacina(x);
int ry = radacina(y);
cout << (rx == ry ? "DA" : "NU") << '\n';
}
}
}