Submission #976365

#TimeUsernameProblemLanguageResultExecution timeMemory
976365UnforgettableplGame (APIO22_game)C++17
2 / 100
1 ms356 KiB
#include <bits/stdc++.h> using namespace std; #define int long long vector<int> adj[1001]; int K,N; void init(int32_t n, int32_t k) { N=n;K=k; for(int i=0;i<k-1;i++)adj[i].emplace_back(i+1); } vector<pair<bool,bool>> visited; vector<int> ans; int DFS(int x){ if(visited[x].second)return 0; if(visited[x].first){ans.emplace_back(x);return x;} visited[x].first=true; for(int&i:adj[x]){ int temp = DFS(i); if(temp==0)continue; if(temp==-1)return -1; ans.emplace_back(x); if(x==temp)return -1; return temp; } visited[x].first=false; visited[x].second=true; return 0; } int32_t add_teleporter(int32_t u, int32_t v) { visited = vector<pair<bool,bool>>(N); adj[u].emplace_back(v); DFS(0); return min(1,(int32_t)ans.size()); } //namespace { // // int32_t read_int() { // int32_t x; // if (scanf("%d", &x) != 1) { // fprintf(stderr, "Error while reading input\n"); // exit(1); // } // return x; // } // //} // namespace // //int32_t main() { // int32_t N = read_int(); // int32_t M = read_int(); // int32_t K = read_int(); // std::vector<int32_t> u(M), v(M); // for (int32_t i = 0; i < M; ++i) { // u[i] = read_int(); // v[i] = read_int(); // } // // init(N, K); // int32_t i; // for (i = 0; i < M; ++i) { // int32_t 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...