Pagini recente » Cod sursa (job #1359362) | Cod sursa (job #2589909) | Cod sursa (job #1931276) | Cod sursa (job #2834696) | Cod sursa (job #1236103)
#include <fstream>
#include <iostream>
#include <vector>
#include <bitset>
#include <string.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <deque>
using namespace std;
const char infile[] = "disjoint.in";
const char outfile[] = "disjoint.out";
ifstream fin(infile);
ofstream fout(outfile);
const int MAXN = 100005;
const int oo = 0x3f3f3f3f;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
const inline int min(const int &a, const int &b) { if( a > b ) return b; return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b; return a; }
const inline void Get_min(int &a, const int b) { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b) { if( a < b ) a = b; }
class DisjointSets {
public:
DisjointSets(int _N) {
father.resize(_N + 1);
N = _N;
for(int i = 1 ; i <= N ; ++ i)
father[i] = i;
}
void Unite(int x, int y) {
father[Find(x)] = Find(y);
}
int Find(int x) {
if(father[x] != x)
father[x] = Find(father[x]);
return father[x];
}
private:
vector <int> father;
int N;
};
int N, M;
int main() {
fin >> N >> M;
DisjointSets D(N);
for(; M -- ;) {
int op, x, y;
fin >> op >> x >> y;
if(op == 1)
D.Unite(x, y);
else fout << ((D.Find(x) == D.Find(y)) ? "DA" : "NU") << '\n';
}
fin.close();
fout.close();
return 0;
}