#include "game.h"
#include "bits/stdc++.h"
using namespace std;
const int inf = 1e9;
int n, k;
vector<vector<int>> g;
vector<int> start;
queue<int> q;
void init(int _n, int _k) {
n = _n, k = _k;
start = vector(n, -inf);
for (int i = 0; i < k; i++) start[i] = i;
g.assign(n, vector<int>());
}
int add_teleporter(int u, int v) {
if (u == v and u < k) return 1;
if (u == v) return 0;
g[u].emplace_back(v);
if (v < k and v <= start[u]) return 1;
// if (start[u] <= start[v]) return 0;
q.push(v);
vector<bool> vis(n); vis[u] = true;
while (!q.empty()) {
int v = q.front(); q.pop();
vis[v] = true;
// cout << u << ' ' << v << ' ' << start[u] << endl;
start[v] = max(start[v], start[u]);
if (v < k and v <= start[u]) return 1;
for (int x: g[v]) { // mb tl
if (vis[x]) continue;
// if (x < k and x <= start[u]) return 1;
if (start[x] <= start[u]) q.push(x);
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |