# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
53482 | jwvg0425 | Toy Train (IOI17_train) | C++17 | 3739 ms | 1904 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 "train.h"
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int n, m, D[5010], U[5010], InQ[5010], C[5010];
vector<int>E[5010], F[5010];
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = a.size();
m = u.size();
int i, j, k;
for (i = 0; i < n; i++) {
if (r[i] == 1)D[i] = 1;
else D[i] = 0;
}
queue<int>Q;
for (i = 0; i < m; i++) {
E[u[i]].push_back(v[i]);
F[v[i]].push_back(u[i]);
}
for (i = 0; i < n; i++) {
if (a[i] == 1) {
for (auto &t : E[i]) {
if (D[i] < D[t] + r[i]) {
Q.push(i);
InQ[i] = 1;
break;
}
}
}
if (a[i] == 0) {
int ck = 0;
for (auto &t : E[i]) {
if (D[i] >= D[t] + r[i])C[i]++;
}
if (C[i] == 0) {
Q.push(i);
InQ[i] = 1;
}
}
}
int cc = 0;
while (!Q.empty()) {
int x = Q.front();
Q.pop();
InQ[x] = 0;
if (a[x] == 1) {
int d = -1e9;
for (auto &t : E[x]) {
d = max(d, D[t] + r[x]);
}
d = min(d, n);
if (D[x] == d) {
cc++;
continue;
}
int od = D[x];
D[x] = d;
for (auto &t : F[x]) {
if (a[t] == 1) {
if (D[t] < r[t] + d) {
if (!InQ[t]) {
InQ[t] = 1;
Q.push(t);
}
}
}
else {
if (D[t] >= r[t] + od && D[t] < r[t] + d) {
C[t]--;
if (!C[t]) {
if (!InQ[t]) {
InQ[t] = 1;
Q.push(t);
}
}
}
}
}
}
else {
int d = 1e9;
for (auto &t : E[x]) {
d = min(d, D[t] + r[x]);
}
d = min(d, n);
if (D[x] == d) {
cc++;
continue;
}
C[x] = 0;
for (auto &t : E[x]) {
if (d >= D[t] + r[x])C[x]++;
}
int od = D[x];
D[x] = d;
for (auto &t : F[x]) {
if (a[t] == 1) {
if (D[t] < r[t] + d) {
if (!InQ[t]) {
InQ[t] = 1;
Q.push(t);
}
}
}
else {
int u = D[t];
if (D[t] >= r[t] + od && D[t] < r[t] + d) {
C[t]--;
if (!C[t]) {
if (!InQ[t]) {
InQ[t] = 1;
Q.push(t);
}
}
}
}
}
D[x] = d;
}
}
vector<int>res(n);
for (i = 0; i < n; i++) {
if (D[i] >= n)res[i] = 1;
else res[i] = 0;
}
return res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |