Pagini recente » Cod sursa (job #2059798) | Cod sursa (job #2738282) | Cod sursa (job #2784871) | Cod sursa (job #1999619) | Cod sursa (job #3224896)
#include <bits/stdc++.h>
#include <unordered_map>
#define nmax 100007
#define MOD 9901
#define INF 2012345678
#define ll long long
using namespace std;
//#define fin cin
//#define fout cout
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n;
int t[nmax];
int FindRoot(int x)
{
int y, rad;
rad = x;
while (t[rad] != 0)
rad = t[rad];
while (x != rad)
{
y = t[x];
t[x] = rad;
x = y;
}
return rad;
}
void Union(int x, int y)
{
t[y] = x;
}
int main()
{
int task, x, y, Q;
fin >> n >> Q;
while (Q--)
{
fin >> task >> x >> y;
x = FindRoot(x);
y = FindRoot(y);
if (task == 1)
Union(x, y);
else if (x != y)
fout << "NU\n";
else
fout << "DA\n";
}
fout.close();
fin.close();
return 0;
}