#include "bits/extc++.h"
using namespace std;
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t;
((cerr << " | " << u), ...);
cerr << endl;
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& arr) {
out << "[";
for (int i = 0; i < sz(arr); i++) {
if (i) {
out << " ";
}
out << arr[i];
}
return out << "]";
}
vector<int> solve_must_vis(const vector<pair<int, int>>& edges,
const vector<vector<int>>& igraph,
const vector<int>& arr,
int team,
const vector<int>& nodes) {
int n = sz(arr);
int o_deg[n] {};
for (auto& [u, v] : edges) {
o_deg[u]++;
}
int co_deg[n] {};
bool queued[n] {};
vector<int> q;
auto push = [&](int u) -> void {
if (queued[u]) {
return;
}
queued[u] = true;
q.push_back(u);
};
for (auto& a : nodes) {
push(a);
}
while (sz(q)) {
int u = q.back();
q.pop_back();
for (auto& v : igraph[u]) {
co_deg[v]++;
if (arr[v] == team) {
push(v);
} else {
if (co_deg[v] == o_deg[v]) {
push(v);
}
}
}
}
vector<int> ans;
for (int i = 0; i < n; i++) {
if (queued[i]) {
ans.push_back(i);
}
}
return ans;
}
vector<int> who_wins(vector<int> arr,
vector<int> is_charging,
vector<int> edges_u,
vector<int> edges_v) {
int n = sz(arr), m = sz(edges_u);
vector<pair<int, int>> edges;
for (int i = 0; i < m; i++) {
edges.emplace_back(edges_u[i], edges_v[i]);
}
vector<vector<int>> igraph(n);
for (auto& [u, v] : edges) {
igraph[v].push_back(u);
}
for (int iter = 0; iter <= n; iter++) {
vector<int> charging;
for (int i = 0; i < n; i++) {
if (is_charging[i]) {
charging.push_back(i);
}
}
auto must_charge = solve_must_vis(edges, igraph, arr, 1, charging);
dbg(must_charge);
bool is_must_charge[n] {};
for (auto& a : must_charge) {
is_must_charge[a] = true;
}
vector<int> wont_charge;
for (int i = 0; i < n; i++) {
if (!is_must_charge[i]) {
wont_charge.push_back(i);
}
}
auto all_wont_charge =
solve_must_vis(edges, igraph, arr, 0, wont_charge);
bool c_wont_charge[n] {};
for (auto& a : all_wont_charge) {
c_wont_charge[a] = true;
}
bool changed = false;
for (auto& a : charging) {
if (c_wont_charge[a]) {
is_charging[a] = false;
changed = true;
}
}
if (changed) {
continue;
}
vector<int> ans(n, 1);
for (auto& a : all_wont_charge) {
ans[a] = 0;
}
return ans;
}
assert(false);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
852 KB |
Output is correct |
2 |
Correct |
4 ms |
980 KB |
Output is correct |
3 |
Correct |
4 ms |
852 KB |
Output is correct |
4 |
Correct |
4 ms |
980 KB |
Output is correct |
5 |
Correct |
4 ms |
972 KB |
Output is correct |
6 |
Correct |
4 ms |
852 KB |
Output is correct |
7 |
Correct |
3 ms |
976 KB |
Output is correct |
8 |
Correct |
3 ms |
900 KB |
Output is correct |
9 |
Correct |
3 ms |
896 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
276 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
1312 KB |
Output is correct |
2 |
Correct |
172 ms |
1328 KB |
Output is correct |
3 |
Correct |
268 ms |
1316 KB |
Output is correct |
4 |
Correct |
5 ms |
1232 KB |
Output is correct |
5 |
Correct |
6 ms |
1232 KB |
Output is correct |
6 |
Correct |
6 ms |
1256 KB |
Output is correct |
7 |
Correct |
5 ms |
1232 KB |
Output is correct |
8 |
Correct |
5 ms |
1232 KB |
Output is correct |
9 |
Correct |
5 ms |
1232 KB |
Output is correct |
10 |
Correct |
5 ms |
1232 KB |
Output is correct |
11 |
Correct |
5 ms |
1232 KB |
Output is correct |
12 |
Correct |
4 ms |
1232 KB |
Output is correct |
13 |
Correct |
5 ms |
1232 KB |
Output is correct |
14 |
Correct |
5 ms |
1232 KB |
Output is correct |
15 |
Correct |
5 ms |
1232 KB |
Output is correct |
16 |
Correct |
5 ms |
1232 KB |
Output is correct |
17 |
Correct |
5 ms |
1232 KB |
Output is correct |
18 |
Correct |
383 ms |
1044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1108 KB |
Output is correct |
2 |
Correct |
5 ms |
1104 KB |
Output is correct |
3 |
Correct |
5 ms |
1260 KB |
Output is correct |
4 |
Correct |
5 ms |
1256 KB |
Output is correct |
5 |
Correct |
5 ms |
1224 KB |
Output is correct |
6 |
Correct |
5 ms |
1232 KB |
Output is correct |
7 |
Correct |
5 ms |
1232 KB |
Output is correct |
8 |
Correct |
5 ms |
1232 KB |
Output is correct |
9 |
Correct |
5 ms |
1248 KB |
Output is correct |
10 |
Correct |
5 ms |
1256 KB |
Output is correct |
11 |
Correct |
5 ms |
1256 KB |
Output is correct |
12 |
Correct |
7 ms |
1232 KB |
Output is correct |
13 |
Correct |
5 ms |
1232 KB |
Output is correct |
14 |
Correct |
7 ms |
1104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1232 KB |
Output is correct |
2 |
Correct |
5 ms |
1256 KB |
Output is correct |
3 |
Correct |
5 ms |
1232 KB |
Output is correct |
4 |
Correct |
5 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
3 ms |
852 KB |
Output is correct |
7 |
Correct |
3 ms |
888 KB |
Output is correct |
8 |
Correct |
4 ms |
980 KB |
Output is correct |
9 |
Correct |
3 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
472 KB |
Output is correct |
11 |
Correct |
3 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
852 KB |
Output is correct |
2 |
Correct |
4 ms |
980 KB |
Output is correct |
3 |
Correct |
4 ms |
852 KB |
Output is correct |
4 |
Correct |
4 ms |
980 KB |
Output is correct |
5 |
Correct |
4 ms |
972 KB |
Output is correct |
6 |
Correct |
4 ms |
852 KB |
Output is correct |
7 |
Correct |
3 ms |
976 KB |
Output is correct |
8 |
Correct |
3 ms |
900 KB |
Output is correct |
9 |
Correct |
3 ms |
896 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
852 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
276 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
80 ms |
1312 KB |
Output is correct |
33 |
Correct |
172 ms |
1328 KB |
Output is correct |
34 |
Correct |
268 ms |
1316 KB |
Output is correct |
35 |
Correct |
5 ms |
1232 KB |
Output is correct |
36 |
Correct |
6 ms |
1232 KB |
Output is correct |
37 |
Correct |
6 ms |
1256 KB |
Output is correct |
38 |
Correct |
5 ms |
1232 KB |
Output is correct |
39 |
Correct |
5 ms |
1232 KB |
Output is correct |
40 |
Correct |
5 ms |
1232 KB |
Output is correct |
41 |
Correct |
5 ms |
1232 KB |
Output is correct |
42 |
Correct |
5 ms |
1232 KB |
Output is correct |
43 |
Correct |
4 ms |
1232 KB |
Output is correct |
44 |
Correct |
5 ms |
1232 KB |
Output is correct |
45 |
Correct |
5 ms |
1232 KB |
Output is correct |
46 |
Correct |
5 ms |
1232 KB |
Output is correct |
47 |
Correct |
5 ms |
1232 KB |
Output is correct |
48 |
Correct |
5 ms |
1232 KB |
Output is correct |
49 |
Correct |
383 ms |
1044 KB |
Output is correct |
50 |
Correct |
4 ms |
1108 KB |
Output is correct |
51 |
Correct |
5 ms |
1104 KB |
Output is correct |
52 |
Correct |
5 ms |
1260 KB |
Output is correct |
53 |
Correct |
5 ms |
1256 KB |
Output is correct |
54 |
Correct |
5 ms |
1224 KB |
Output is correct |
55 |
Correct |
5 ms |
1232 KB |
Output is correct |
56 |
Correct |
5 ms |
1232 KB |
Output is correct |
57 |
Correct |
5 ms |
1232 KB |
Output is correct |
58 |
Correct |
5 ms |
1248 KB |
Output is correct |
59 |
Correct |
5 ms |
1256 KB |
Output is correct |
60 |
Correct |
5 ms |
1256 KB |
Output is correct |
61 |
Correct |
7 ms |
1232 KB |
Output is correct |
62 |
Correct |
5 ms |
1232 KB |
Output is correct |
63 |
Correct |
7 ms |
1104 KB |
Output is correct |
64 |
Correct |
5 ms |
1232 KB |
Output is correct |
65 |
Correct |
5 ms |
1256 KB |
Output is correct |
66 |
Correct |
5 ms |
1232 KB |
Output is correct |
67 |
Correct |
5 ms |
1108 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
3 ms |
852 KB |
Output is correct |
70 |
Correct |
3 ms |
888 KB |
Output is correct |
71 |
Correct |
4 ms |
980 KB |
Output is correct |
72 |
Correct |
3 ms |
980 KB |
Output is correct |
73 |
Correct |
1 ms |
472 KB |
Output is correct |
74 |
Correct |
3 ms |
856 KB |
Output is correct |
75 |
Correct |
139 ms |
1504 KB |
Output is correct |
76 |
Correct |
183 ms |
1532 KB |
Output is correct |
77 |
Correct |
271 ms |
1528 KB |
Output is correct |
78 |
Correct |
286 ms |
1532 KB |
Output is correct |
79 |
Correct |
277 ms |
1556 KB |
Output is correct |
80 |
Correct |
6 ms |
1464 KB |
Output is correct |
81 |
Correct |
8 ms |
1504 KB |
Output is correct |
82 |
Correct |
6 ms |
1492 KB |
Output is correct |
83 |
Correct |
6 ms |
1488 KB |
Output is correct |
84 |
Correct |
6 ms |
1488 KB |
Output is correct |
85 |
Correct |
6 ms |
1464 KB |
Output is correct |
86 |
Correct |
6 ms |
1488 KB |
Output is correct |
87 |
Correct |
6 ms |
1488 KB |
Output is correct |
88 |
Correct |
9 ms |
1460 KB |
Output is correct |
89 |
Correct |
6 ms |
1488 KB |
Output is correct |
90 |
Correct |
12 ms |
1464 KB |
Output is correct |
91 |
Correct |
11 ms |
1464 KB |
Output is correct |
92 |
Correct |
20 ms |
1500 KB |
Output is correct |
93 |
Correct |
19 ms |
1504 KB |
Output is correct |
94 |
Correct |
23 ms |
1532 KB |
Output is correct |
95 |
Correct |
26 ms |
1460 KB |
Output is correct |
96 |
Correct |
58 ms |
1404 KB |
Output is correct |
97 |
Correct |
371 ms |
1508 KB |
Output is correct |
98 |
Correct |
607 ms |
1484 KB |
Output is correct |
99 |
Correct |
715 ms |
1472 KB |
Output is correct |
100 |
Correct |
393 ms |
1144 KB |
Output is correct |