Pagini recente » Cod sursa (job #480257) | Cod sursa (job #387251) | Cod sursa (job #3197097) | Cod sursa (job #318760) | Cod sursa (job #3233871)
#include <fstream>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <cstring>
#include <map>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#define oo 2000000
#define MOD 1000000007
using namespace std;
ifstream fin("a.in");
ofstream fout("a.out");
int t[100000];
int rang[100000];
int n, m,op,x,y;
int find(int k)
{
if (t[k] == 0)
return k;
else
{
int x = find(t[k]);
t[k] = x;
return x;
}
}
void Union(int x,int y)
{
if (rang[x] > rang[y])
{
t[y] = x;
}
else
{
t[x] = y;
if (rang[x] == rang[y])
rang[y]++;
}
}
int main()
{
fin >> n >> m;
while (m--)
{
fin >> op >> x >> y;
x = find(x);
y = find(y);
if (op == 2)
{
if (x == y)
{
fout << "DA" << endl;
}
else
{
fout << "NU" << endl;
}
}
else
{
if (x != y)
Union(x, y);
}
}
}