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>
using namespace std;
using i32 = int;
using i64 = long long;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = V<V<T>>;
template <typename T>
using VVV = V<V<V<T>>>;
#define OVERLOAD4(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, l, r) for (i32 i = (i32)(l); i < (i32)(r); ++i)
#define REP(...) OVERLOAD4(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER2(i, n) for (i32 i = (i32)(n) - 1; i >= 0; --i)
#define PER3(i, l, r) for (i32 i = (i32)(r) - 1; i >= (i32)(l); --i)
#define PER(...) OVERLOAD4(__VA_ARGS__, PER3, PER2)(__VA_ARGS__)
#define ALL(x) begin(x), end(x)
#define LEN(x) (i32)size(x)
template <typename T>
bool chmin(T &x, const T &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
void dbg(i32 x) { cerr << x; }
void dbg(i64 x) { cerr << x; }
template <typename T>
void dbg(const V<T> &arr) {
cerr << "[";
REP(i, LEN(arr)) {
if (i) {
cerr << ", ";
}
dbg(arr[i]);
}
cerr << "]";
}
void debug() {}
template <typename Head, typename... Tail>
void debug(const Head &head, const Tail &... tail) {
dbg(head);
if (sizeof...(Tail)) {
cerr << ", ";
} else {
cerr << '\n';
}
debug(tail...);
}
#ifdef DEBUGF
#define DBG(...) do { cerr << #__VA_ARGS__ << " : "; debug(__VA_ARGS__); } while (false)
#else
#define DBG(...) (void)0
#endif
#include "train.h"
V<i32> who_wins(V<i32> a, V<i32> r, V<i32> u, V<i32> v) {
i32 n = LEN(a);
i32 m = LEN(u);
VV<i32> g(n), rg(n);
REP(i, m) {
g[u[i]].push_back(v[i]);
rg[v[i]].push_back(u[i]);
}
assert(count(ALL(r), 1) == 1);
i32 en = (i32)(find(ALL(r), 1) - r.begin());
V<i32> deg(n);
REP(i, n) {
deg[i] = LEN(g[i]);
}
V<i32> reach(n, 0);
queue<i32> que;
que.push(en);
while (!que.empty()) {
i32 v = que.front();
que.pop();
if (reach[v]) {
continue;
}
reach[v] = 1;
for (i32 u : g[v]) {
if (a[u] == 0) {
if (--deg[u] == 0) {
que.push(u);
}
} else {
que.push(u);
}
}
}
bool enw = false;
if (a[en] == 0) {
enw = true;
for (i32 u : g[en]) {
if (!reach[u]) {
enw = false;
}
}
} else {
for (i32 u : g[en]) {
if (reach[u]) {
enw = true;
}
}
}
V<i32> ans(n, 0);
if (enw) {
ans = reach;
}
return ans;
}
# | 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... |