Pagini recente » Cod sursa (job #768928) | Cod sursa (job #325725) | Cod sursa (job #449685) | Cod sursa (job #2091842) | Cod sursa (job #3227522)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#undef INT_MAX
#define INT_MAX LLONG_MAX
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vvpii vector<vector<pii>>
#define vvi vector<vector<int>>
#define vf vector<long double>
#define vvf vector<vector<long double>>
#define float long double
#define fs first
#define sc second
#define pb push_back
#define lsh(i) (1 << (i))
#define fi(i, n) for (int i = 0; (i) < (n); ++(i))
#define fe(x, a) for (auto &x : (a))
#define all(a) (a).begin(), (a).end()
#define YES (cout << "YES\n")
#define NO (cout << "NO\n")
#define gcd(a, b) __gcd(a, b)
const int mod = (1e9 + 7);
const int pmod = 998244353;
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct custom_hash
{
static uint64_t splitmix64(uint64_t x)
{
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
{
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
size_t operator()(pair<uint64_t, uint64_t> x) const
{
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x.first + FIXED_RANDOM) ^ (splitmix64(x.second + FIXED_RANDOM) >> 1);
}
};
#define us unordered_set<int, custom_hash>
int find(vi& a, int x)
{
if(a[x] == x)
{
return x;
}
return a[x] = find(a, a[x]);
}
signed main(signed argc, char **argv)
{
// #ifndef ONLINE_JUDGE
freopen("disjoint.in", "r", stdin);
freopen("disjoint.out", "w", stdout);
// #endif // ! ONLINE_JUDGE
if (argc > 1)
{
freopen(argv[1], "r", stdin);
freopen(argv[2], "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
vi a(n + 1);
fi(i, n + 1)
{
a[i] = i;
}
while(m--)
{
int op, x, y;
cin >> op >> x >> y;
if(op == 1)
{
a[find(a, x)] = find(a, y);
}
else
{
cout << (find(a, x) == find(a, y) ? "DA\n" : "NU\n");
}
}
return 0;
}