Pagini recente » Cod sursa (job #1958070) | Cod sursa (job #2868451) | Cod sursa (job #224348) | Cod sursa (job #3218975) | Cod sursa (job #2640228)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 100005;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
vector<int> t;
int find(int x)
{
if(t[x] == 0)
return x;
t[x] = find(t[x]);
return t[x];
}
void unite(int x, int y)
{
int rx = find(x);
int ry = find(y);
t[rx] = ry;
}
int main()
{
int n, q;
fin >> n >> q;
t.resize(n + 1);
while(q--)
{
int t, x, y;
fin >> t >> x >> y;
if(t == 1)
unite(x, y);
else
{
if(find(x) == find(y))
fout << "DA\n";
else
fout << "NU\n";
}
}
return 0;
}