Pagini recente » Cod sursa (job #2657067) | Cod sursa (job #5473) | Cod sursa (job #117100) | Cod sursa (job #2447600) | Cod sursa (job #2931980)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define d double
#define in int
#define si(x) scanf('%d', &x)
#define sl(x) scanf('%lld', &x)
#define ss(s) scanf('%s', s)
#define pi(x) printf('%d', x)
#define pl(x) printf('%lld', x)
#define ps(s) printf('%s', s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
#define modulo 1000000007
#define FOR(i,a,b) for(int i=a;i<=b;i++)
typedef vector<pii> vpii;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
vector<int>father;
vector<int> height;
int n,k, operatie, x, y;
class Union_Find{
public:
int Find(int x){
if(father[x] == 0)
return x;
father[x] = Find(father[x]);
return father[x];
}
void Union(int x, int y){
int rx = Find(x);
int ry = Find(y);
if(height[rx] < height[ry]){
father[rx] = ry;
}
else if(height[rx] > height[ry])
father[ry] = rx;
else{
father[ry] = rx;
height[rx]+=1;
}
}
void menu(){
fin>>n>>k;
father = vector<int> (n+1, 0);
height = vector<int> (n+1, 0);
for(int i=1;i<=k;++i){
fin>>operatie>>x>>y;
if(operatie == 1){
Union(x,y);
}
else{
if(Find(x) == Find(y))
fout<<"DA\n";
else
fout<<"NU\n";
}
}
}
};
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
Union_Find x;
x.menu();
fin.close();
fout.close();
return 0;
}