#include "game.h"
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<vector<int>> adj;
bool has_cycle = false; // avoid re-computing answer if its already true
bool dfs(int u, set<int> &vis, int head) {
bool does = false;
vis.insert(u);
for (auto &v : adj[u]) {
if (v <= head && head < k) return true;
if (vis.count(v)) continue;
does = does || dfs(v, vis, head);
if (does) break;
}
return does;
}
bool check() {
for (int i = 0; i < k; i++) {
set<int> vis;
if (dfs(i, vis, i)) return true;
}
return false;
}
void init(int N, int K) {
n = N; k = K;
adj.assign(n, vector<int>());
for (int i = 1; i < k; i++) {
adj[i - 1].push_back(i);
}
}
int add_teleporter(int u, int v) {
adj[u].push_back(v);
if (!has_cycle) has_cycle = has_cycle || check();
return has_cycle;
}
# | 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... |