#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 : rg[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 |
1 |
Runtime error |
3 ms |
1880 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
2676 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
2140 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1372 KB |
Output is correct |
2 |
Correct |
5 ms |
1604 KB |
Output is correct |
3 |
Correct |
5 ms |
1624 KB |
Output is correct |
4 |
Correct |
4 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
448 KB |
Output is correct |
6 |
Correct |
2 ms |
1116 KB |
Output is correct |
7 |
Correct |
3 ms |
1116 KB |
Output is correct |
8 |
Correct |
4 ms |
1216 KB |
Output is correct |
9 |
Correct |
3 ms |
1116 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
1880 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |