Submission #978283

#TimeUsernameProblemLanguageResultExecution timeMemory
978283mannshah1211Game (APIO22_game)C++17
0 / 100
0 ms344 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; class dsu { public: vector<int> par, sz; void build(int n) { par.resize(n); sz.resize(n); iota(par.begin(), par.end(), 0); } int find(int v) { return (par[v] == v) ? v : par[v] = find(par[v]); } bool unite(int u, int v) { u = find(u); v = find(v); if (u == v) { return false; } if (sz[u] < sz[v]) { swap(u, v); } sz[u] += sz[v]; par[v] = u; return true; } bool same(int u, int v) { return (find(u) == find(v)); } }; dsu ds; int _k; void init(int n, int k) { ds.build(n); _k = k; } int add_teleporter(int u, int v) { for (int i = 0; i < _k; i++) { if (ds.same(i, u) && ds.same(i, v)) { return true; } } ds.unite(u, v); return false; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...