Submission #584085

#TimeUsernameProblemLanguageResultExecution timeMemory
584085PiejanVDCToy Train (IOI17_train)C++17
0 / 100
5 ms1236 KiB
#include <bits/stdc++.h> #include "train.h" using namespace std; vector<int>tim; vector<bool>vis(15); vector<int>s,a,r; vector<int>adj[15]; vector<int>ans(15,2); int t = 1; bool dfs(int u) { vis[u] = 1; if(ans[u] != 2) { vis[u] = 0; return ans[u]; } tim[u] = t++; if(r[u]) s.push_back(t-1); bool ok; if(a[u]) { ok = 0; for(auto z : adj[u]) if(!vis[z]) { ok |= dfs(z); if(ok) break; } else { if(!s.empty() && tim[z] <= s.back()) ok = 1; } } else { ok = 1; for(auto z : adj[u]) if(!vis[z]) { ok &= dfs(z); if(!ok) break; } else { if(!s.empty() && tim[z] <= s.back()) ok &= 1; } } if(r[u]) s.pop_back(); tim[u] = 0; vis[u] = 0; return ok; } vector<int>who_wins(vector<int>A, vector<int>R, vector<int>u, vector<int>v) { r = R; a = A; int n = r.size(); int m = u.size(); for(int i = 0 ; i < m ; i++) { adj[u[i]].push_back(v[i]); } vector<int>x; for(int i = 0 ; i < n ; i++) x.push_back(i); random_shuffle(x.begin(),x.end()); for(int y = 0 ; y < n ; y++) { int i = x[y]; t = 1; tim.clear(); tim.resize(n,0); ans[i] = dfs(i); } return ans; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...