Submission #598559

#TimeUsernameProblemLanguageResultExecution timeMemory
598559MKopchevGame (APIO22_game)C++17
30 / 100
4083 ms9200 KiB
#include "game.h" #include<bits/stdc++.h> using namespace std; const int nmax=3e5+42; int mem_n,mem_k; vector<int> adj[nmax]; void init(int n, int k) { mem_n=n; mem_k=k; for(int i=1;i<k;i++) adj[i-1].push_back(i); } bool ok; bool been[nmax]; int ROOT; void dfs(int node) { if(ok)return; if(node<ROOT) { ok=1; return; } if(been[node]) { ok=(node==ROOT); return; } been[node]=1; for(auto w:adj[node]) dfs(w); } int add_teleporter(int u, int v) { adj[u].push_back(v); ok=0; for(int i=0;i<mem_n;i++) been[i]=0; for(ROOT=mem_k-1;ROOT>=0;ROOT--) dfs(ROOT); return ok; } /* 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() { 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; } */
#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...