Pagini recente » Cod sursa (job #2103834) | Cod sursa (job #95630) | Cod sursa (job #305176) | Cod sursa (job #2837368) | Cod sursa (job #2837333)
#include <bits/stdc++.h>
#define ull unsigned long long
#define FILES freopen("disjoint.in","r",stdin);\
freopen("disjoint.out","w",stdout);
#define CMAX 1000000
#define fastio std::ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL);
#define mp make_pair
#define INF 999999999999999
#define void inline void
#define mod 1000000007
#define ll long long
#define MAX 100000
#define SMAX 500000
#define pb push_back
#define add emplace_back
using namespace std;
int n,m,root[MAX+5];
int Find(int x)
{
if(x != root[x]) return root[x] = Find(root[x]);
else return x;
}
int main()
{
fastio
FILES
cin >> n >> m;
for(int i = 1;i <= n; ++i) root[i] = i;
for(int i = 1;i <= m; ++i)
{
int a,b,c;
cin >> a >> b >> c;
if(a == 1)
{
int r = Find(b),r2 = Find(c);
if(r > r2) root[r] = r2;
else root[r2] = r;
}
else
{
int r = Find(b),r2 = Find(c);
if(r == r2) cout << "DA\n";
else cout << "NU\n";
}
}
}