#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<int>& arr,
int team,
const vector<int>& nodes) {
int n = sz(arr);
vector<int> igraph[n];
int o_deg[n] {};
for (auto& [u, v] : edges) {
igraph[v].push_back(u);
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]);
}
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, 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, 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 |
6 ms |
852 KB |
Output is correct |
2 |
Correct |
9 ms |
852 KB |
Output is correct |
3 |
Correct |
8 ms |
948 KB |
Output is correct |
4 |
Correct |
7 ms |
904 KB |
Output is correct |
5 |
Correct |
5 ms |
956 KB |
Output is correct |
6 |
Correct |
6 ms |
904 KB |
Output is correct |
7 |
Correct |
4 ms |
852 KB |
Output is correct |
8 |
Correct |
6 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
4 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
1 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 |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
378 ms |
1324 KB |
Output is correct |
2 |
Correct |
885 ms |
1332 KB |
Output is correct |
3 |
Correct |
1334 ms |
1336 KB |
Output is correct |
4 |
Correct |
7 ms |
1308 KB |
Output is correct |
5 |
Correct |
9 ms |
1232 KB |
Output is correct |
6 |
Correct |
13 ms |
1360 KB |
Output is correct |
7 |
Correct |
6 ms |
1232 KB |
Output is correct |
8 |
Correct |
6 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 |
5 ms |
1232 KB |
Output is correct |
13 |
Correct |
6 ms |
1252 KB |
Output is correct |
14 |
Correct |
6 ms |
1232 KB |
Output is correct |
15 |
Correct |
6 ms |
1232 KB |
Output is correct |
16 |
Correct |
5 ms |
1232 KB |
Output is correct |
17 |
Correct |
6 ms |
1232 KB |
Output is correct |
18 |
Execution timed out |
2086 ms |
1012 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1108 KB |
Output is correct |
2 |
Correct |
6 ms |
1104 KB |
Output is correct |
3 |
Correct |
7 ms |
1232 KB |
Output is correct |
4 |
Correct |
7 ms |
1232 KB |
Output is correct |
5 |
Correct |
7 ms |
1232 KB |
Output is correct |
6 |
Correct |
8 ms |
1264 KB |
Output is correct |
7 |
Correct |
7 ms |
1232 KB |
Output is correct |
8 |
Correct |
8 ms |
1232 KB |
Output is correct |
9 |
Correct |
9 ms |
1232 KB |
Output is correct |
10 |
Correct |
6 ms |
1232 KB |
Output is correct |
11 |
Correct |
6 ms |
1260 KB |
Output is correct |
12 |
Correct |
5 ms |
1232 KB |
Output is correct |
13 |
Correct |
6 ms |
1252 KB |
Output is correct |
14 |
Correct |
5 ms |
1104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1232 KB |
Output is correct |
2 |
Correct |
5 ms |
1232 KB |
Output is correct |
3 |
Correct |
6 ms |
1232 KB |
Output is correct |
4 |
Correct |
5 ms |
1104 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
4 ms |
852 KB |
Output is correct |
7 |
Correct |
4 ms |
980 KB |
Output is correct |
8 |
Correct |
4 ms |
980 KB |
Output is correct |
9 |
Correct |
4 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
852 KB |
Output is correct |
2 |
Correct |
9 ms |
852 KB |
Output is correct |
3 |
Correct |
8 ms |
948 KB |
Output is correct |
4 |
Correct |
7 ms |
904 KB |
Output is correct |
5 |
Correct |
5 ms |
956 KB |
Output is correct |
6 |
Correct |
6 ms |
904 KB |
Output is correct |
7 |
Correct |
4 ms |
852 KB |
Output is correct |
8 |
Correct |
6 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
852 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
4 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 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 |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 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 |
1 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 |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
378 ms |
1324 KB |
Output is correct |
33 |
Correct |
885 ms |
1332 KB |
Output is correct |
34 |
Correct |
1334 ms |
1336 KB |
Output is correct |
35 |
Correct |
7 ms |
1308 KB |
Output is correct |
36 |
Correct |
9 ms |
1232 KB |
Output is correct |
37 |
Correct |
13 ms |
1360 KB |
Output is correct |
38 |
Correct |
6 ms |
1232 KB |
Output is correct |
39 |
Correct |
6 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 |
5 ms |
1232 KB |
Output is correct |
44 |
Correct |
6 ms |
1252 KB |
Output is correct |
45 |
Correct |
6 ms |
1232 KB |
Output is correct |
46 |
Correct |
6 ms |
1232 KB |
Output is correct |
47 |
Correct |
5 ms |
1232 KB |
Output is correct |
48 |
Correct |
6 ms |
1232 KB |
Output is correct |
49 |
Execution timed out |
2086 ms |
1012 KB |
Time limit exceeded |
50 |
Halted |
0 ms |
0 KB |
- |