Submission #839079

#TimeUsernameProblemLanguageResultExecution timeMemory
839079mohammad_kilaniToy Train (IOI17_train)C++17
100 / 100
337 ms1704 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++){ out[i] = (int)g[i].size(); if(r[i]){ out[i] = 0; ans[i] = 1; q.push(i); } } 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) continue; out[pre]--; if(a[pre]){ out[pre] = 0; ans[pre] = 1; q.push(pre); continue; } if(out[pre] == 0){ ans[pre] = 1; q.push(pre); } } } for(int i = 0 ;i < n;i++){ if(ans[i] == -1) 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...