Pagini recente » Cod sursa (job #2254289) | Cod sursa (job #1550712) | Cod sursa (job #1552345) | Cod sursa (job #1224294) | Cod sursa (job #3215868)
#include <bits/stdc++.h>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
const int NMAX = 1e5 + 30;
const int INF = 0x3f3f3f3f;
int n, m, root[NMAX], op, x, y;
void read()
{
in >> n>>m;
}
int getroot(int x)
{
if (root[x]==x)
return x;
return root[x] = getroot(root[x]);
}
void solve()
{
for (int i=1; i<=n; root[i] = i, i++);
while (m--)
{
in>>op>>x>>y;
x = getroot(x);
y = getroot(y);
if (op==1) root[x] = y;
else {x==y ? out<<"DA"<<'\n' : out<<"NU"<<'\n';}
}
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
read();
solve();
return 0;
}