# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1063492 | Zicrus | Toy Train (IOI17_train) | C++17 | 1347 ms | 2008 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, res;
vector<vector<ll>> adj, revAdj;
vector<bool> vst;
bool dfsCyc(ll cur, ll root) {
vst[cur] = true;
for (auto &e : adj[cur]) {
if (e == root) return true;
if (vst[e] || r[e]) continue;
if (dfsCyc(e, root)) return true;
}
return false;
}
void dfsRes(ll cur) {
vst[cur] = true;
res[cur] = 0;
for (auto &e : revAdj[cur]) {
if (vst[e]) continue;
dfsRes(e);
}
}
vector<int> who_wins(vector<int> A, vector<int> R, vector<int> u, vector<int> v) {
n = A.size();
a = A; r = R;
res = vector<int>(n, 1);
vst = vector<bool>(n);
adj = vector<vector<ll>>(n);
revAdj = vector<vector<ll>>(n);
for (int i = 0; i < u.size(); i++) {
adj[u[i]].push_back(v[i]);
revAdj[v[i]].push_back(u[i]);
}
for (int i = 0; i < n; i++) {
if (r[i]) continue;
vst = vector<bool>(n);
if (dfsCyc(i, i)) {
vst = vector<bool>(n);
dfsRes(i);
}
}
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... |