Submission #839055

#TimeUsernameProblemLanguageResultExecution timeMemory
839055mohammad_kilaniToy Train (IOI17_train)C++17
22 / 100
237 ms1680 KiB
#include "train.h" #include <bits/stdc++.h> using namespace std; const int N = 5010; int n; vector< int > ans , g[N] , g2[N] , r , a; void make(){ ans = vector< int > (n , -1); vector< int > out(n , 0); queue < int > q; for(int i = 0 ;i < n;i++){ if(r[i]) continue; for(int j = 0 ;j < (int)g[i].size();j++){ if(a[i]){ if(r[g[i][j]]){ out[i] = 0; ans[i] = 1; q.push(i); break; } out[i]++; } else{ if(r[g[i][j]]) continue; out[i]++; } } if(out[i] == 0){ q.push(i); if(ans[i] == -1){ ans[i] = a[i] ^ 1; } } } int node; while(!q.empty()){ node = q.front(); q.pop(); for(int pre , i = 0 ;i < (int)g2[node].size();i++){ pre = g2[node][i]; if(out[pre] == 0 || r[pre]) continue; out[pre]--; if(ans[node] == a[pre]){ out[pre] = 0; ans[pre] = a[pre]; q.push(pre); continue; } if(out[pre] == 0){ ans[pre] = a[pre] ^ 1; q.push(pre); } } } for(int i = 0 ;i < n;i++){ if(r[i]){ ans[i] = 1; continue; } if(out[i] > 0){ ans[i] = 0; } } } std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) { n = (int)a.size(); ans.resize(n , -1); ::r = r; ::a = a; for(int i = 0 ;i < (int)u.size();i++){ g[u[i]].push_back(v[i]); g2[v[i]].push_back(u[i]); } bool found = true , good; while(found){ make(); found = false; for(int i = 0 ;i < n;i++){ if(!::r[i]) continue; good = false; for(int j = 0 ;j < (int)g[i].size();j++){ if(ans[g[i][j]] == a[i]){ good = true; break; } } if(good){ if(!a[i]) found = true, ::r[i] = false; } else{ if(a[i]) found = true, ::r[i] = false; } } } 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...