# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
65505 | gs13068 | Toy Train (IOI17_train) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <vector>
using namespace std;
int d[2][5005], s[5005];
vector<int> g[5005];
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int i, j, n = a.size(), m = u.size();
int *p = d[0], *q = d[1], *t;
for (i = 0; i < m; i++) g[u[i]].push_back(v[i]);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (a[j] == 1) {
q[j] = 0;
for (auto t : g[j]) if (p[t] > q[j]) q[j] = p[t];
}
else {
q[j] = 1e9;
for (auto t : g[j]) if (p[t] < q[j]) q[j] = p[t];
}
if (r[j]) q[j]++;
}
t = p; p = q; q = t;
}
for (i = 0; i < n; i++) s[i] = p[i];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (a[j] == 1) {
q[j] = 0;
for (auto t : g[j]) if (p[t] > q[j]) q[j] = p[t];
}
else {
q[j] = 1e9;
for (auto t : g[j]) if (p[t] < q[j]) q[j] = p[t];
}
if (r[j]) q[j]++;
}
t = p; p = q; q = t;
}
vector<int> ans;
for (i = 0; i < n; i++) ans.push_back(p[i] > s[i] ? 1 : 2)
return ans;
}