#include "train.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n, m;
vector<vector<int>> graph, graphr;
vector<bool> active;
vector<int> A;
template<int P>
vector<bool> reachable_from(vector<int> S){
vector<bool> bl(n, 0);
vector<int> cnt(n, 0);
for(int i = 0; i < n; i++) if(active[i]) for(int x: graph[i]) cnt[i]+=active[x];
function<void(int)> dfs = [&](int nd){
if(!active[nd]) return;
if(A[nd] != P){
cnt[nd]--;
if(cnt[nd] > 0) return;
}
if(bl[nd]) return;
bl[nd] = 1;
for(int x: graphr[nd]) dfs(x);
};
for(int x: S){
cnt[x] = 0;
dfs(x);
}
return bl;
}
vector<int> who_wins(vector<int> _A, vector<int> R, vector<int> U, vector<int> V){
swap(A, _A);
n = A.size(), m = U.size();
graph.resize(n), graphr.resize(n);
active.assign(n, 1);
for(int i = 0; i < m; i++) graph[U[i]].pb(V[i]), graphr[V[i]].pb(U[i]);
vector<int> ans(n, 1);
while(1){
vector<int> S;
for(int i = 0; i < n; i++) if(active[i] && R[i]) S.pb(i);
auto bl = reachable_from<1>(S);
S.clear();
for(int i = 0; i < n; i++) if(active[i] && !bl[i]) S.pb(i);
if(S.empty()) break;
bl = reachable_from<0>(S);
for(int i = 0; i < n; i++) if(bl[i]) active[i] = 0, ans[i] = 0;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1108 KB |
Output is correct |
2 |
Correct |
7 ms |
1108 KB |
Output is correct |
3 |
Correct |
6 ms |
1108 KB |
Output is correct |
4 |
Correct |
5 ms |
1080 KB |
Output is correct |
5 |
Correct |
6 ms |
1076 KB |
Output is correct |
6 |
Correct |
5 ms |
1188 KB |
Output is correct |
7 |
Correct |
5 ms |
1116 KB |
Output is correct |
8 |
Correct |
5 ms |
1108 KB |
Output is correct |
9 |
Correct |
5 ms |
1104 KB |
Output is correct |
10 |
Correct |
6 ms |
1108 KB |
Output is correct |
11 |
Correct |
5 ms |
1080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 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 |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
167 ms |
1968 KB |
Output is correct |
2 |
Correct |
311 ms |
1924 KB |
Output is correct |
3 |
Correct |
435 ms |
1916 KB |
Output is correct |
4 |
Correct |
9 ms |
1720 KB |
Output is correct |
5 |
Correct |
10 ms |
1724 KB |
Output is correct |
6 |
Correct |
10 ms |
1628 KB |
Output is correct |
7 |
Correct |
9 ms |
1620 KB |
Output is correct |
8 |
Correct |
9 ms |
1620 KB |
Output is correct |
9 |
Correct |
8 ms |
1568 KB |
Output is correct |
10 |
Correct |
9 ms |
1492 KB |
Output is correct |
11 |
Correct |
9 ms |
1568 KB |
Output is correct |
12 |
Correct |
7 ms |
1464 KB |
Output is correct |
13 |
Correct |
11 ms |
1720 KB |
Output is correct |
14 |
Correct |
8 ms |
1748 KB |
Output is correct |
15 |
Correct |
9 ms |
1748 KB |
Output is correct |
16 |
Correct |
9 ms |
1724 KB |
Output is correct |
17 |
Correct |
12 ms |
1728 KB |
Output is correct |
18 |
Correct |
503 ms |
1424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1460 KB |
Output is correct |
2 |
Correct |
9 ms |
1416 KB |
Output is correct |
3 |
Correct |
10 ms |
1596 KB |
Output is correct |
4 |
Correct |
11 ms |
1596 KB |
Output is correct |
5 |
Correct |
9 ms |
1624 KB |
Output is correct |
6 |
Correct |
9 ms |
1492 KB |
Output is correct |
7 |
Correct |
9 ms |
1492 KB |
Output is correct |
8 |
Correct |
8 ms |
1492 KB |
Output is correct |
9 |
Correct |
9 ms |
1468 KB |
Output is correct |
10 |
Correct |
9 ms |
1620 KB |
Output is correct |
11 |
Correct |
9 ms |
1620 KB |
Output is correct |
12 |
Correct |
8 ms |
1592 KB |
Output is correct |
13 |
Correct |
9 ms |
1588 KB |
Output is correct |
14 |
Correct |
8 ms |
1460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1584 KB |
Output is correct |
2 |
Correct |
9 ms |
1748 KB |
Output is correct |
3 |
Correct |
9 ms |
1600 KB |
Output is correct |
4 |
Correct |
8 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
5 ms |
1156 KB |
Output is correct |
7 |
Correct |
6 ms |
1044 KB |
Output is correct |
8 |
Correct |
7 ms |
1080 KB |
Output is correct |
9 |
Correct |
5 ms |
1072 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
6 ms |
932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1108 KB |
Output is correct |
2 |
Correct |
7 ms |
1108 KB |
Output is correct |
3 |
Correct |
6 ms |
1108 KB |
Output is correct |
4 |
Correct |
5 ms |
1080 KB |
Output is correct |
5 |
Correct |
6 ms |
1076 KB |
Output is correct |
6 |
Correct |
5 ms |
1188 KB |
Output is correct |
7 |
Correct |
5 ms |
1116 KB |
Output is correct |
8 |
Correct |
5 ms |
1108 KB |
Output is correct |
9 |
Correct |
5 ms |
1104 KB |
Output is correct |
10 |
Correct |
6 ms |
1108 KB |
Output is correct |
11 |
Correct |
5 ms |
1080 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
300 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 |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
1 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 |
1 ms |
300 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 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 |
167 ms |
1968 KB |
Output is correct |
33 |
Correct |
311 ms |
1924 KB |
Output is correct |
34 |
Correct |
435 ms |
1916 KB |
Output is correct |
35 |
Correct |
9 ms |
1720 KB |
Output is correct |
36 |
Correct |
10 ms |
1724 KB |
Output is correct |
37 |
Correct |
10 ms |
1628 KB |
Output is correct |
38 |
Correct |
9 ms |
1620 KB |
Output is correct |
39 |
Correct |
9 ms |
1620 KB |
Output is correct |
40 |
Correct |
8 ms |
1568 KB |
Output is correct |
41 |
Correct |
9 ms |
1492 KB |
Output is correct |
42 |
Correct |
9 ms |
1568 KB |
Output is correct |
43 |
Correct |
7 ms |
1464 KB |
Output is correct |
44 |
Correct |
11 ms |
1720 KB |
Output is correct |
45 |
Correct |
8 ms |
1748 KB |
Output is correct |
46 |
Correct |
9 ms |
1748 KB |
Output is correct |
47 |
Correct |
9 ms |
1724 KB |
Output is correct |
48 |
Correct |
12 ms |
1728 KB |
Output is correct |
49 |
Correct |
503 ms |
1424 KB |
Output is correct |
50 |
Correct |
8 ms |
1460 KB |
Output is correct |
51 |
Correct |
9 ms |
1416 KB |
Output is correct |
52 |
Correct |
10 ms |
1596 KB |
Output is correct |
53 |
Correct |
11 ms |
1596 KB |
Output is correct |
54 |
Correct |
9 ms |
1624 KB |
Output is correct |
55 |
Correct |
9 ms |
1492 KB |
Output is correct |
56 |
Correct |
9 ms |
1492 KB |
Output is correct |
57 |
Correct |
8 ms |
1492 KB |
Output is correct |
58 |
Correct |
9 ms |
1468 KB |
Output is correct |
59 |
Correct |
9 ms |
1620 KB |
Output is correct |
60 |
Correct |
9 ms |
1620 KB |
Output is correct |
61 |
Correct |
8 ms |
1592 KB |
Output is correct |
62 |
Correct |
9 ms |
1588 KB |
Output is correct |
63 |
Correct |
8 ms |
1460 KB |
Output is correct |
64 |
Correct |
9 ms |
1584 KB |
Output is correct |
65 |
Correct |
9 ms |
1748 KB |
Output is correct |
66 |
Correct |
9 ms |
1600 KB |
Output is correct |
67 |
Correct |
8 ms |
1492 KB |
Output is correct |
68 |
Correct |
1 ms |
316 KB |
Output is correct |
69 |
Correct |
5 ms |
1156 KB |
Output is correct |
70 |
Correct |
6 ms |
1044 KB |
Output is correct |
71 |
Correct |
7 ms |
1080 KB |
Output is correct |
72 |
Correct |
5 ms |
1072 KB |
Output is correct |
73 |
Correct |
2 ms |
468 KB |
Output is correct |
74 |
Correct |
6 ms |
932 KB |
Output is correct |
75 |
Correct |
297 ms |
1708 KB |
Output is correct |
76 |
Correct |
368 ms |
1916 KB |
Output is correct |
77 |
Correct |
513 ms |
1908 KB |
Output is correct |
78 |
Correct |
534 ms |
1876 KB |
Output is correct |
79 |
Correct |
526 ms |
1904 KB |
Output is correct |
80 |
Correct |
13 ms |
1636 KB |
Output is correct |
81 |
Correct |
11 ms |
1592 KB |
Output is correct |
82 |
Correct |
10 ms |
1620 KB |
Output is correct |
83 |
Correct |
10 ms |
1580 KB |
Output is correct |
84 |
Correct |
12 ms |
1748 KB |
Output is correct |
85 |
Correct |
9 ms |
1592 KB |
Output is correct |
86 |
Correct |
11 ms |
1596 KB |
Output is correct |
87 |
Correct |
9 ms |
1588 KB |
Output is correct |
88 |
Correct |
13 ms |
1504 KB |
Output is correct |
89 |
Correct |
12 ms |
1596 KB |
Output is correct |
90 |
Correct |
17 ms |
1492 KB |
Output is correct |
91 |
Correct |
15 ms |
1604 KB |
Output is correct |
92 |
Correct |
29 ms |
1636 KB |
Output is correct |
93 |
Correct |
33 ms |
1612 KB |
Output is correct |
94 |
Correct |
33 ms |
1580 KB |
Output is correct |
95 |
Correct |
35 ms |
1604 KB |
Output is correct |
96 |
Correct |
108 ms |
1620 KB |
Output is correct |
97 |
Correct |
449 ms |
1620 KB |
Output is correct |
98 |
Correct |
736 ms |
1584 KB |
Output is correct |
99 |
Correct |
834 ms |
1664 KB |
Output is correct |
100 |
Correct |
522 ms |
1424 KB |
Output is correct |