#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using ld = long double;
template<typename T1, typename T2> bool chkmin(T1 &x, T2 y) {
return y < x ? (x = y, true) : false;
}
template<typename T1, typename T2> bool chkmax(T1 &x, T2 y) {
return y > x ? (x = y, true) : false;
}
void debug_out() {
cerr << endl;
}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) {
cerr << ' ' << A;
debug_out(B...);
}
template<typename T> void mdebug_out(T* a, int n) {
for (int i = 0; i < n; ++i) {
cerr << a[i] << ' ';
}
cerr << endl;
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n)
#else
#define debug(...) 1337
#define mdebug(a, n) 1337
#endif
template<typename T> ostream& operator << (ostream& stream, const vector<T> &v) {
for (auto& x : v) {
stream << x << ' ';
}
return stream;
}
template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) {
return stream << p.first << ' ' << p.second;
}
const int maxN = 5003;
using Set = bitset<maxN>;
vector<int> who_wins(vector<int> owner, vector<int> _Z, vector<int> e1, vector<int> e2) {
int n = owner.size();
int m = e1.size();
vector<int> GR[n];
vector<int> outdeg0(n);
for (int j = 0; j < m; ++j) {
GR[e2[j]].push_back(e1[j]);
}
for (int v = 0; v < n; ++v) {
owner[v] ^= 1;
}
Set Z;
for (int v = 0; v < n; ++v) {
Z[v] = _Z[v];
}
Set enabled;
for (int v = 0; v < n; ++v) {
enabled[v] = true;
}
auto f = [&](int i, Set S) -> Set {
vector<int> stk;
vector<int> in_stk(n, false);
auto add = [&](int v) {
assert(enabled[v]);
if (!in_stk[v]) {
in_stk[v] = true;
stk.push_back(v);
}
};
for (int v = 0; v < n; ++v) {
if (S[v] && enabled[v]) {
add(v);
}
}
vector<int> outdeg(n);
for (int v = 0; v < n; ++v) {
outdeg[v] = outdeg0[v];
}
Set ans;
while (!stk.empty()) {
int v = stk.back();
stk.pop_back();
ans[v] = 1;
for (int u : GR[v]) if (enabled[u]) {
if (owner[u] == i) {
add(u);
} else if (--outdeg[u] == 0) {
add(u);
}
}
}
return ans;
};
while (true) {
//cerr << "enabled: "; for (int v = 0; v < n; ++v) cerr << enabled[v]; cerr << endl;
fill(all(outdeg0), 0);
for (int v = 0; v < n; ++v) if (enabled[v]) {
for (int u : GR[v]) if (enabled[u]) {
++outdeg0[u];
}
}
Z &= enabled;
if (!Z.count()) {
return vector<int>(n, 0);
}
Set TZ = f(0, Z);
Set B = TZ;
for (int v = 0; v < n; ++v) if (enabled[v]) {
B[v] = !B[v];
}
//cerr << "B: "; for (int v = 0; v < n; ++v) cerr << B[v]; cerr << endl;
if (!B.count()) {
vector<int> ans(n);
for (int v = 0; v < n; ++v) {
ans[v] = enabled[v];
}
return ans;
}
Set TB = f(1, B);
//cerr << "TB: "; for (int v = 0; v < n; ++v) cerr << TB[v]; cerr << endl;
enabled &= ~TB;
}
throw;
}
#ifdef DEBUG
int32_t main() {
#ifdef DEBUG
freopen("in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n), r(n);
for (auto& x : a) cin >> x;
for (auto& x : r) cin >> x;
vector<int> e1(m), e2(m);
for (int j = 0; j < m; ++j) {
cin >> e1[j] >> e2[j];
}
cout << who_wins(a, r, e1, e2) << '\n';
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
844 KB |
Output is correct |
2 |
Correct |
8 ms |
936 KB |
Output is correct |
3 |
Correct |
6 ms |
844 KB |
Output is correct |
4 |
Correct |
6 ms |
928 KB |
Output is correct |
5 |
Correct |
6 ms |
844 KB |
Output is correct |
6 |
Correct |
5 ms |
824 KB |
Output is correct |
7 |
Correct |
5 ms |
844 KB |
Output is correct |
8 |
Correct |
6 ms |
844 KB |
Output is correct |
9 |
Correct |
5 ms |
912 KB |
Output is correct |
10 |
Correct |
5 ms |
844 KB |
Output is correct |
11 |
Correct |
4 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
1092 KB |
Output is correct |
2 |
Correct |
253 ms |
1100 KB |
Output is correct |
3 |
Correct |
331 ms |
1100 KB |
Output is correct |
4 |
Correct |
8 ms |
1100 KB |
Output is correct |
5 |
Correct |
9 ms |
1228 KB |
Output is correct |
6 |
Correct |
9 ms |
1244 KB |
Output is correct |
7 |
Correct |
8 ms |
1200 KB |
Output is correct |
8 |
Correct |
8 ms |
1228 KB |
Output is correct |
9 |
Correct |
8 ms |
1268 KB |
Output is correct |
10 |
Correct |
8 ms |
1228 KB |
Output is correct |
11 |
Correct |
8 ms |
1228 KB |
Output is correct |
12 |
Correct |
7 ms |
1228 KB |
Output is correct |
13 |
Correct |
8 ms |
1256 KB |
Output is correct |
14 |
Correct |
8 ms |
1208 KB |
Output is correct |
15 |
Correct |
8 ms |
1228 KB |
Output is correct |
16 |
Correct |
8 ms |
1228 KB |
Output is correct |
17 |
Correct |
8 ms |
1212 KB |
Output is correct |
18 |
Correct |
430 ms |
992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
976 KB |
Output is correct |
2 |
Correct |
8 ms |
1100 KB |
Output is correct |
3 |
Correct |
8 ms |
1228 KB |
Output is correct |
4 |
Correct |
9 ms |
1216 KB |
Output is correct |
5 |
Correct |
11 ms |
1228 KB |
Output is correct |
6 |
Correct |
8 ms |
1196 KB |
Output is correct |
7 |
Correct |
11 ms |
1228 KB |
Output is correct |
8 |
Correct |
8 ms |
1232 KB |
Output is correct |
9 |
Correct |
8 ms |
1228 KB |
Output is correct |
10 |
Correct |
8 ms |
1228 KB |
Output is correct |
11 |
Correct |
8 ms |
1212 KB |
Output is correct |
12 |
Correct |
9 ms |
1228 KB |
Output is correct |
13 |
Correct |
9 ms |
1284 KB |
Output is correct |
14 |
Correct |
8 ms |
1176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1100 KB |
Output is correct |
2 |
Correct |
8 ms |
1228 KB |
Output is correct |
3 |
Correct |
9 ms |
1228 KB |
Output is correct |
4 |
Correct |
8 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
4 ms |
848 KB |
Output is correct |
7 |
Correct |
6 ms |
832 KB |
Output is correct |
8 |
Correct |
6 ms |
856 KB |
Output is correct |
9 |
Correct |
6 ms |
844 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
844 KB |
Output is correct |
2 |
Correct |
8 ms |
936 KB |
Output is correct |
3 |
Correct |
6 ms |
844 KB |
Output is correct |
4 |
Correct |
6 ms |
928 KB |
Output is correct |
5 |
Correct |
6 ms |
844 KB |
Output is correct |
6 |
Correct |
5 ms |
824 KB |
Output is correct |
7 |
Correct |
5 ms |
844 KB |
Output is correct |
8 |
Correct |
6 ms |
844 KB |
Output is correct |
9 |
Correct |
5 ms |
912 KB |
Output is correct |
10 |
Correct |
5 ms |
844 KB |
Output is correct |
11 |
Correct |
4 ms |
844 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
145 ms |
1092 KB |
Output is correct |
33 |
Correct |
253 ms |
1100 KB |
Output is correct |
34 |
Correct |
331 ms |
1100 KB |
Output is correct |
35 |
Correct |
8 ms |
1100 KB |
Output is correct |
36 |
Correct |
9 ms |
1228 KB |
Output is correct |
37 |
Correct |
9 ms |
1244 KB |
Output is correct |
38 |
Correct |
8 ms |
1200 KB |
Output is correct |
39 |
Correct |
8 ms |
1228 KB |
Output is correct |
40 |
Correct |
8 ms |
1268 KB |
Output is correct |
41 |
Correct |
8 ms |
1228 KB |
Output is correct |
42 |
Correct |
8 ms |
1228 KB |
Output is correct |
43 |
Correct |
7 ms |
1228 KB |
Output is correct |
44 |
Correct |
8 ms |
1256 KB |
Output is correct |
45 |
Correct |
8 ms |
1208 KB |
Output is correct |
46 |
Correct |
8 ms |
1228 KB |
Output is correct |
47 |
Correct |
8 ms |
1228 KB |
Output is correct |
48 |
Correct |
8 ms |
1212 KB |
Output is correct |
49 |
Correct |
430 ms |
992 KB |
Output is correct |
50 |
Correct |
7 ms |
976 KB |
Output is correct |
51 |
Correct |
8 ms |
1100 KB |
Output is correct |
52 |
Correct |
8 ms |
1228 KB |
Output is correct |
53 |
Correct |
9 ms |
1216 KB |
Output is correct |
54 |
Correct |
11 ms |
1228 KB |
Output is correct |
55 |
Correct |
8 ms |
1196 KB |
Output is correct |
56 |
Correct |
11 ms |
1228 KB |
Output is correct |
57 |
Correct |
8 ms |
1232 KB |
Output is correct |
58 |
Correct |
8 ms |
1228 KB |
Output is correct |
59 |
Correct |
8 ms |
1228 KB |
Output is correct |
60 |
Correct |
8 ms |
1212 KB |
Output is correct |
61 |
Correct |
9 ms |
1228 KB |
Output is correct |
62 |
Correct |
9 ms |
1284 KB |
Output is correct |
63 |
Correct |
8 ms |
1176 KB |
Output is correct |
64 |
Correct |
9 ms |
1100 KB |
Output is correct |
65 |
Correct |
8 ms |
1228 KB |
Output is correct |
66 |
Correct |
9 ms |
1228 KB |
Output is correct |
67 |
Correct |
8 ms |
1100 KB |
Output is correct |
68 |
Correct |
1 ms |
332 KB |
Output is correct |
69 |
Correct |
4 ms |
848 KB |
Output is correct |
70 |
Correct |
6 ms |
832 KB |
Output is correct |
71 |
Correct |
6 ms |
856 KB |
Output is correct |
72 |
Correct |
6 ms |
844 KB |
Output is correct |
73 |
Correct |
2 ms |
460 KB |
Output is correct |
74 |
Correct |
5 ms |
796 KB |
Output is correct |
75 |
Correct |
224 ms |
1256 KB |
Output is correct |
76 |
Correct |
285 ms |
1228 KB |
Output is correct |
77 |
Correct |
375 ms |
1300 KB |
Output is correct |
78 |
Correct |
379 ms |
1348 KB |
Output is correct |
79 |
Correct |
409 ms |
1348 KB |
Output is correct |
80 |
Correct |
9 ms |
1228 KB |
Output is correct |
81 |
Correct |
10 ms |
1228 KB |
Output is correct |
82 |
Correct |
10 ms |
1296 KB |
Output is correct |
83 |
Correct |
9 ms |
1232 KB |
Output is correct |
84 |
Correct |
10 ms |
1300 KB |
Output is correct |
85 |
Correct |
9 ms |
1228 KB |
Output is correct |
86 |
Correct |
10 ms |
1220 KB |
Output is correct |
87 |
Correct |
9 ms |
1208 KB |
Output is correct |
88 |
Correct |
14 ms |
1208 KB |
Output is correct |
89 |
Correct |
9 ms |
1228 KB |
Output is correct |
90 |
Correct |
15 ms |
1292 KB |
Output is correct |
91 |
Correct |
14 ms |
1240 KB |
Output is correct |
92 |
Correct |
25 ms |
1304 KB |
Output is correct |
93 |
Correct |
26 ms |
1228 KB |
Output is correct |
94 |
Correct |
32 ms |
1228 KB |
Output is correct |
95 |
Correct |
27 ms |
1296 KB |
Output is correct |
96 |
Correct |
92 ms |
1100 KB |
Output is correct |
97 |
Correct |
345 ms |
1288 KB |
Output is correct |
98 |
Correct |
597 ms |
1260 KB |
Output is correct |
99 |
Correct |
646 ms |
1348 KB |
Output is correct |
100 |
Correct |
396 ms |
996 KB |
Output is correct |