#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
#define ii pair<int, int>
#define x first
#define y second
#define vii vector<ii>
#define pb push_back
#define all(x) x.begin(), x.end()
#define loop(i,s,e) for(int i=s;i<e;++i)
#define loopr(i,s,e) for(int i=e-1;i>=s;--i)
#define chkmin(a,b) a = min(a,b)
#define chkmax(a,b) a = max(a,b)
using namespace std;
const int INF = 1e9;
int n;
vvi ag;
vi basedeg;
vi a,r;
vi res;
vb f(vb& s, int who){ // a = 1, b = 0
vb check(n,0);
vi deg(n);
loop(i,0,n) deg[i] = basedeg[i];
queue<int> q;
loop(i,0,n) if(s[i]) q.push(i), check[i]=1, deg[i]=0;
while(q.size()){
int cur = q.front(); q.pop();
for(auto nei:ag[cur]){
if (res[nei]!=-1) continue;
if (a[nei]==who){
if (!check[nei]){
check[nei] = 1;
q.push(nei);
}
}
else{
if (--deg[nei]==0){
check[nei] = 1;
q.push(nei);
}
}
}
}
return check;
}
vi who_wins(vi aa, vi rr, vi u, vi v) {
a = aa, r = rr;
n = a.size();
basedeg.resize(n); ag.resize(n);
loop(i,0,u.size()){
int a = u[i], b = v[i];
basedeg[a]++;
ag[b].pb(a);
}
res.resize(n,-1);
while(1){
vb b(n);
loop(i,0,n) if(r[i] && res[i]==-1){
b[i] = 1;
}
b = f(b, 1);
int cnt = 0, sz=0, cnt2=0;
loop(i,0,n) if(res[i]==-1) cnt2+=b[i], b[i]=!b[i], sz++;
if (cnt2==sz || sz==0){
loop(i,0,n) if(res[i]==-1) res[i]=1;
break;
}
b = f(b,0);
loop(i,0,n) if(b[i]) cnt++;
loop(i,0,n) if(b[i]) {
for(auto nei:ag[i]) basedeg[nei]--;
res[i]=0;
}
}
return res;
}
/*
clear
g++ c.cpp grader.cpp -o c ; ./c
6 7
0 1 0 0 1 0
1 0 0 0 0 1
0 1
1 2
2 3
3 1
4 5
5 5
4 1
*/
Compilation message
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:12:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | #define loop(i,s,e) for(int i=s;i<e;++i)
......
57 | loop(i,0,u.size()){
| ~~~~~~~~~~~~
train.cpp:57:5: note: in expansion of macro 'loop'
57 | loop(i,0,u.size()){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1024 KB |
Output is correct |
2 |
Correct |
9 ms |
1024 KB |
Output is correct |
3 |
Correct |
6 ms |
1024 KB |
Output is correct |
4 |
Correct |
6 ms |
896 KB |
Output is correct |
5 |
Correct |
7 ms |
896 KB |
Output is correct |
6 |
Correct |
6 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
1024 KB |
Output is correct |
8 |
Correct |
6 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
896 KB |
Output is correct |
10 |
Correct |
5 ms |
896 KB |
Output is correct |
11 |
Correct |
5 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
1408 KB |
Output is correct |
2 |
Correct |
200 ms |
1528 KB |
Output is correct |
3 |
Correct |
276 ms |
1412 KB |
Output is correct |
4 |
Correct |
9 ms |
1408 KB |
Output is correct |
5 |
Correct |
10 ms |
1408 KB |
Output is correct |
6 |
Correct |
10 ms |
1408 KB |
Output is correct |
7 |
Correct |
9 ms |
1408 KB |
Output is correct |
8 |
Correct |
9 ms |
1408 KB |
Output is correct |
9 |
Correct |
8 ms |
1280 KB |
Output is correct |
10 |
Correct |
9 ms |
1280 KB |
Output is correct |
11 |
Correct |
8 ms |
1280 KB |
Output is correct |
12 |
Correct |
8 ms |
1280 KB |
Output is correct |
13 |
Correct |
9 ms |
1408 KB |
Output is correct |
14 |
Correct |
9 ms |
1408 KB |
Output is correct |
15 |
Correct |
9 ms |
1408 KB |
Output is correct |
16 |
Correct |
9 ms |
1408 KB |
Output is correct |
17 |
Correct |
9 ms |
1408 KB |
Output is correct |
18 |
Correct |
395 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1152 KB |
Output is correct |
2 |
Correct |
11 ms |
1280 KB |
Output is correct |
3 |
Correct |
9 ms |
1280 KB |
Output is correct |
4 |
Correct |
9 ms |
1408 KB |
Output is correct |
5 |
Correct |
9 ms |
1280 KB |
Output is correct |
6 |
Correct |
9 ms |
1408 KB |
Output is correct |
7 |
Correct |
9 ms |
1280 KB |
Output is correct |
8 |
Correct |
8 ms |
1280 KB |
Output is correct |
9 |
Correct |
8 ms |
1280 KB |
Output is correct |
10 |
Correct |
9 ms |
1536 KB |
Output is correct |
11 |
Correct |
9 ms |
1408 KB |
Output is correct |
12 |
Correct |
9 ms |
1408 KB |
Output is correct |
13 |
Correct |
9 ms |
1408 KB |
Output is correct |
14 |
Correct |
9 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1408 KB |
Output is correct |
2 |
Correct |
9 ms |
1408 KB |
Output is correct |
3 |
Correct |
9 ms |
1408 KB |
Output is correct |
4 |
Correct |
8 ms |
1280 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
896 KB |
Output is correct |
7 |
Correct |
7 ms |
896 KB |
Output is correct |
8 |
Correct |
6 ms |
892 KB |
Output is correct |
9 |
Correct |
6 ms |
896 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
6 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1024 KB |
Output is correct |
2 |
Correct |
9 ms |
1024 KB |
Output is correct |
3 |
Correct |
6 ms |
1024 KB |
Output is correct |
4 |
Correct |
6 ms |
896 KB |
Output is correct |
5 |
Correct |
7 ms |
896 KB |
Output is correct |
6 |
Correct |
6 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
1024 KB |
Output is correct |
8 |
Correct |
6 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
896 KB |
Output is correct |
10 |
Correct |
5 ms |
896 KB |
Output is correct |
11 |
Correct |
5 ms |
896 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
0 ms |
256 KB |
Output is correct |
23 |
Correct |
0 ms |
256 KB |
Output is correct |
24 |
Correct |
1 ms |
256 KB |
Output is correct |
25 |
Correct |
1 ms |
256 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
256 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
1 ms |
256 KB |
Output is correct |
32 |
Correct |
103 ms |
1408 KB |
Output is correct |
33 |
Correct |
200 ms |
1528 KB |
Output is correct |
34 |
Correct |
276 ms |
1412 KB |
Output is correct |
35 |
Correct |
9 ms |
1408 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
10 ms |
1408 KB |
Output is correct |
38 |
Correct |
9 ms |
1408 KB |
Output is correct |
39 |
Correct |
9 ms |
1408 KB |
Output is correct |
40 |
Correct |
8 ms |
1280 KB |
Output is correct |
41 |
Correct |
9 ms |
1280 KB |
Output is correct |
42 |
Correct |
8 ms |
1280 KB |
Output is correct |
43 |
Correct |
8 ms |
1280 KB |
Output is correct |
44 |
Correct |
9 ms |
1408 KB |
Output is correct |
45 |
Correct |
9 ms |
1408 KB |
Output is correct |
46 |
Correct |
9 ms |
1408 KB |
Output is correct |
47 |
Correct |
9 ms |
1408 KB |
Output is correct |
48 |
Correct |
9 ms |
1408 KB |
Output is correct |
49 |
Correct |
395 ms |
1144 KB |
Output is correct |
50 |
Correct |
10 ms |
1152 KB |
Output is correct |
51 |
Correct |
11 ms |
1280 KB |
Output is correct |
52 |
Correct |
9 ms |
1280 KB |
Output is correct |
53 |
Correct |
9 ms |
1408 KB |
Output is correct |
54 |
Correct |
9 ms |
1280 KB |
Output is correct |
55 |
Correct |
9 ms |
1408 KB |
Output is correct |
56 |
Correct |
9 ms |
1280 KB |
Output is correct |
57 |
Correct |
8 ms |
1280 KB |
Output is correct |
58 |
Correct |
8 ms |
1280 KB |
Output is correct |
59 |
Correct |
9 ms |
1536 KB |
Output is correct |
60 |
Correct |
9 ms |
1408 KB |
Output is correct |
61 |
Correct |
9 ms |
1408 KB |
Output is correct |
62 |
Correct |
9 ms |
1408 KB |
Output is correct |
63 |
Correct |
9 ms |
1280 KB |
Output is correct |
64 |
Correct |
9 ms |
1408 KB |
Output is correct |
65 |
Correct |
9 ms |
1408 KB |
Output is correct |
66 |
Correct |
9 ms |
1408 KB |
Output is correct |
67 |
Correct |
8 ms |
1280 KB |
Output is correct |
68 |
Correct |
1 ms |
384 KB |
Output is correct |
69 |
Correct |
5 ms |
896 KB |
Output is correct |
70 |
Correct |
7 ms |
896 KB |
Output is correct |
71 |
Correct |
6 ms |
892 KB |
Output is correct |
72 |
Correct |
6 ms |
896 KB |
Output is correct |
73 |
Correct |
2 ms |
512 KB |
Output is correct |
74 |
Correct |
6 ms |
896 KB |
Output is correct |
75 |
Correct |
181 ms |
1400 KB |
Output is correct |
76 |
Correct |
226 ms |
1528 KB |
Output is correct |
77 |
Correct |
304 ms |
1416 KB |
Output is correct |
78 |
Correct |
302 ms |
1528 KB |
Output is correct |
79 |
Correct |
305 ms |
1528 KB |
Output is correct |
80 |
Correct |
9 ms |
1408 KB |
Output is correct |
81 |
Correct |
10 ms |
1404 KB |
Output is correct |
82 |
Correct |
13 ms |
1408 KB |
Output is correct |
83 |
Correct |
10 ms |
1408 KB |
Output is correct |
84 |
Correct |
10 ms |
1408 KB |
Output is correct |
85 |
Correct |
10 ms |
1408 KB |
Output is correct |
86 |
Correct |
10 ms |
1408 KB |
Output is correct |
87 |
Correct |
9 ms |
1408 KB |
Output is correct |
88 |
Correct |
12 ms |
1408 KB |
Output is correct |
89 |
Correct |
10 ms |
1408 KB |
Output is correct |
90 |
Correct |
15 ms |
1408 KB |
Output is correct |
91 |
Correct |
14 ms |
1408 KB |
Output is correct |
92 |
Correct |
23 ms |
1408 KB |
Output is correct |
93 |
Correct |
24 ms |
1408 KB |
Output is correct |
94 |
Correct |
24 ms |
1408 KB |
Output is correct |
95 |
Correct |
24 ms |
1400 KB |
Output is correct |
96 |
Correct |
88 ms |
1280 KB |
Output is correct |
97 |
Correct |
296 ms |
1400 KB |
Output is correct |
98 |
Correct |
500 ms |
1280 KB |
Output is correct |
99 |
Correct |
574 ms |
1400 KB |
Output is correct |
100 |
Correct |
400 ms |
1024 KB |
Output is correct |