Submission #33919

#TimeUsernameProblemLanguageResultExecution timeMemory
33919imeimi2000Toy Train (IOI17_train)C++14
100 / 100
706 ms3080 KiB
#include "train.h" using namespace std; int n, m; vector<int> edge[5000]; vector<int> redge[5000]; int outdegree[5000]; int stop[5000]; vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { n = a.size(); m = u.size(); for (int i = 0; i < m; ++i) { edge[u[i]].push_back(v[i]); redge[v[i]].push_back(u[i]); } bool loop = true; while (loop) { vector<int> st; for (int i = 0; i < n; ++i) { stop[i] = r[i] ^ 1; outdegree[i] = edge[i].size(); if (r[i]) st.push_back(i); } while (!st.empty()) { int x = st.back(); st.pop_back(); for (int i : redge[x]) { if (stop[i] == 0) continue; --outdegree[i]; if (a[i] == 1 || outdegree[i] == 0) { stop[i] = 0; st.push_back(i); } } } for (int i = 0; i < n; ++i) { if (stop[i] == 1) st.push_back(i); outdegree[i] = edge[i].size(); } while (!st.empty()) { int x = st.back(); st.pop_back(); for (int i : redge[x]) { if (stop[i] == 1) continue; --outdegree[i]; if (a[i] == 0 || outdegree[i] == 0) { stop[i] = 1; st.push_back(i); } } } loop = false; for (int i = 0; i < n; ++i) { if (r[i] && stop[i]) loop = true, r[i] = 0; } } vector<int> ret; ret.resize(n); for (int i = 0; i < n; ++i) { ret[i] = stop[i] ^ 1; } return ret; }
#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...