Pagini recente » Cod sursa (job #1744501) | Cod sursa (job #1967042) | Cod sursa (job #1082983) | Cod sursa (job #2207369) | Cod sursa (job #3029973)
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
ifstream in("f.in");
ofstream out("f.out");
const int NMAX = 1e5 + 5;
const char nl = '\n';
int n, m, father[NMAX];
int root(int x){
if(x == father[x])
return x;
return father[x] = root(father[x]);
}
void unite(int x, int y){
father[root(x)] = root(y);
}
int main()
{
in >> n >> m;
for(int i = 1; i <= n; ++i)
father[i] = i;
for(int i = 1; i <= m; ++i){
int q, x, y;
in >> q >> x >> y;
if(q == 1){
if(root(x) != root(y))
unite(x, y);
}
else{
if(root(x) != root(y))
out << "NU" << nl;
else
out << "DA" << nl;
}
}
return 0;
}