# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1063542 | Zicrus | Toy Train (IOI17_train) | C++17 | 2033 ms | 43000 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 <bits/stdc++.h>
#include "train.h"
using namespace std;
typedef long long ll;
ll n;
vector<int> a, r;
vector<vector<ll>> adj;
int solve(ll cur, vector<int> vst) {
vst[cur] = 1;
if (r[cur]) {
for (auto &e : vst) {
if (e == 1) e = 2;
}
}
int player = a[cur];
for (auto &e : adj[cur]) {
if (player == 1 && vst[e] == 2) return 1;
if (player == 0 && vst[e] == 1) return 0;
}
for (auto &e : adj[cur]) {
if (vst[e]) continue;
int val = solve(e, vst);
if (player == val) return val;
}
return !player;
}
vector<int> who_wins(vector<int> A, vector<int> R, vector<int> u, vector<int> v) {
n = A.size();
a = A; r = R;
vector<int> res(n);
adj = vector<vector<ll>>(n);
for (int i = 0; i < u.size(); i++) {
adj[u[i]].push_back(v[i]);
}
mt19937 mt(75834);
for (auto &e : adj) shuffle(e.begin(), e.end(), mt);
vector<int> vst(n);
for (int i = 0; i < n; i++) {
res[i] = solve(i, vst);
}
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... |