# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
746841 | 2023-05-23T07:08:50 Z | tutis | Game (APIO22_game) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; const int N = 300000; int K; vector<int>adj[N]; vector<int>adj_[N]; int mn[N]; void init(int n, int k) { K = k; for (int i = 0; i < n; i++) mn[i] = k; } int add_teleporter(int u, int v) { adj[u].push_back(v); adj_[v].push_back(u); int x = min(v, mn[v]); int ret = 0; function<void(int)>dfs = [&](int i) { if (x >= mn[i]) return; mn[i] = x; if (i < K && x <= i) { ret = 1; } for (int j : adj[i]) { dfs(j); } }; dfs(u); return ret; } int main() { init(4, 2); cout << add_teleporter(1, 1) << endl; }