Submission #971126

#TimeUsernameProblemLanguageResultExecution timeMemory
971126nguyentunglamGame (APIO22_game)C++17
60 / 100
947 ms7360 KiB
#include "game.h" #include<bits/stdc++.h> using namespace std; const int N = 30'000 + 10, K = 1000 + 10; bitset<N> f[K]; vector<int> adj[N]; bool cycle; int n, k; void expand (int root, int u) { f[root][u] = 1; for(int &v : adj[u]) { if (v == root) cycle = 1; if (!f[root][v]) expand(root, v); } } void add (int u, int v) { adj[u].push_back(v); for(int start = 0; start < k; start++) { if (f[start][u] && v == start) cycle = 1; if (f[start][u] && !f[start][v]) expand(start, v); } } void init(int N, int K) { n = N; k = K; cycle = 0; for(int i = 0; i < k; i++) f[i][i] = 1; for(int i = 0; i + 1 < k; i++) add(i, i + 1); } int add_teleporter(int u, int v) { add(u, v); return cycle; } #ifdef ngu namespace { int read_int() { int x; if (scanf("%d", &x) != 1) { fprintf(stderr, "Error while reading input\n"); exit(1); } return x; } } // namespace int main() { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); int N = read_int(); int M = read_int(); int K = read_int(); std::vector<int> u(M), v(M); for (int i = 0; i < M; ++i) { u[i] = read_int(); v[i] = read_int(); } init(N, K); int i; for (i = 0; i < M; ++i) { int answer = add_teleporter(u[i], v[i]); if (answer != 0 && answer != 1) { i = -1; break; } else if (answer == 1) { break; } } printf("%d\n", i); return 0; } #endif // ngu
#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...