#include "train.h"
#include "bits/stdc++.h"
using namespace std;
vector <int> g[5005];
vector <int> trans[5005];
int own[5005];
int charge[5005];
int n;
int m;
int out[5005];
bool take[5005];
bool del[5005];
int outdeg[5005];
vector <int> Fa(vector <int> v) {
for(int i = 0; i < n; i++) {
out[i] = 0;
take[i] = false;
}
queue <int> q;
for(auto i : v) {
q.push(i);
take[i] = true;
}
while(!q.empty()) {
int i = q.front();
q.pop();
for(auto j : trans[i]) {
if(del[j]) continue;
out[j] += 1;
if(!take[j] && own[j] == 1) {
q.push(j);
take[j] = true;
}
if(!take[j] && out[j] == outdeg[j] && own[j] == 0) {
q.push(j);
take[j] = true;
}
}
}
vector <int> ans;
for(int i = 0; i < n; i++) {
if(take[i]) {
ans.emplace_back(i);
}
}
return ans;
}
vector <int> Fb(vector <int> v) {
for(int i = 0; i < n; i++) {
out[i] = 0;
take[i] = false;
}
queue <int> q;
for(auto i : v) {
q.push(i);
take[i] = true;
}
while(!q.empty()) {
int i = q.front();
q.pop();
for(auto j : trans[i]) {
if(del[j]) continue;
out[j] += 1;
if(!take[j] && own[j] == 0) {
q.push(j);
take[j] = true;
}
if(!take[j] && out[j] == outdeg[j] && own[j] == 1) {
q.push(j);
take[j] = true;
}
}
}
vector <int> ans;
for(int i = 0; i < n; i++) {
if(take[i]) {
ans.emplace_back(i);
}
}
return ans;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
vector <int> ans;
n = a.size();
m = u.size();
ans.resize(n);
for(int i = 0; i < n; i++) {
own[i] = a[i];
charge[i] = r[i];
del[i] = false;
}
for(int i = 0; i < m; i++) {
int p = u[i];
int q = v[i];
g[p].emplace_back(q);
trans[q].emplace_back(p);
++outdeg[p];
}
while(true) {
vector <int> station;
for(int i = 0; i < n; i++) {
if(charge[i] && !del[i]) {
station.emplace_back(i);
}
}
vector <int> P = Fa(station);
vector <int> Q;
for(int i = 0; i < n; i++) {
if(!take[i] && !del[i]) {
Q.emplace_back(i);
}
}
if(Q.empty()) {
for(auto i : P) {
ans[i] = 1;
}
break;
}
vector <int> X = Fb(Q);
for(auto i : X) {
ans[i] = 0;
del[i] = true;
for(auto j : trans[i]) {
--outdeg[j];
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1272 KB |
Output is correct |
2 |
Correct |
10 ms |
1272 KB |
Output is correct |
3 |
Correct |
13 ms |
1472 KB |
Output is correct |
4 |
Correct |
9 ms |
1472 KB |
Output is correct |
5 |
Correct |
10 ms |
1472 KB |
Output is correct |
6 |
Correct |
9 ms |
1472 KB |
Output is correct |
7 |
Correct |
8 ms |
1472 KB |
Output is correct |
8 |
Correct |
10 ms |
1484 KB |
Output is correct |
9 |
Correct |
8 ms |
1484 KB |
Output is correct |
10 |
Correct |
10 ms |
1484 KB |
Output is correct |
11 |
Correct |
8 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1492 KB |
Output is correct |
2 |
Correct |
3 ms |
1492 KB |
Output is correct |
3 |
Correct |
3 ms |
1492 KB |
Output is correct |
4 |
Correct |
2 ms |
1492 KB |
Output is correct |
5 |
Correct |
2 ms |
1492 KB |
Output is correct |
6 |
Correct |
3 ms |
1492 KB |
Output is correct |
7 |
Correct |
3 ms |
1492 KB |
Output is correct |
8 |
Correct |
3 ms |
1492 KB |
Output is correct |
9 |
Correct |
3 ms |
1492 KB |
Output is correct |
10 |
Correct |
4 ms |
1492 KB |
Output is correct |
11 |
Correct |
3 ms |
1492 KB |
Output is correct |
12 |
Correct |
2 ms |
1492 KB |
Output is correct |
13 |
Correct |
2 ms |
1492 KB |
Output is correct |
14 |
Correct |
3 ms |
1492 KB |
Output is correct |
15 |
Correct |
4 ms |
1492 KB |
Output is correct |
16 |
Correct |
2 ms |
1492 KB |
Output is correct |
17 |
Correct |
5 ms |
1492 KB |
Output is correct |
18 |
Correct |
3 ms |
1492 KB |
Output is correct |
19 |
Correct |
4 ms |
1492 KB |
Output is correct |
20 |
Correct |
4 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
1996 KB |
Output is correct |
2 |
Correct |
258 ms |
1996 KB |
Output is correct |
3 |
Correct |
346 ms |
2020 KB |
Output is correct |
4 |
Correct |
14 ms |
2020 KB |
Output is correct |
5 |
Correct |
13 ms |
2020 KB |
Output is correct |
6 |
Correct |
15 ms |
2144 KB |
Output is correct |
7 |
Correct |
15 ms |
2344 KB |
Output is correct |
8 |
Correct |
15 ms |
2556 KB |
Output is correct |
9 |
Correct |
13 ms |
2764 KB |
Output is correct |
10 |
Correct |
16 ms |
2828 KB |
Output is correct |
11 |
Correct |
16 ms |
3076 KB |
Output is correct |
12 |
Correct |
13 ms |
3272 KB |
Output is correct |
13 |
Correct |
15 ms |
3528 KB |
Output is correct |
14 |
Correct |
12 ms |
3724 KB |
Output is correct |
15 |
Correct |
14 ms |
3944 KB |
Output is correct |
16 |
Correct |
13 ms |
4152 KB |
Output is correct |
17 |
Correct |
15 ms |
4360 KB |
Output is correct |
18 |
Correct |
525 ms |
4360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
4360 KB |
Output is correct |
2 |
Correct |
13 ms |
4360 KB |
Output is correct |
3 |
Correct |
11 ms |
4432 KB |
Output is correct |
4 |
Correct |
19 ms |
4436 KB |
Output is correct |
5 |
Correct |
18 ms |
4436 KB |
Output is correct |
6 |
Correct |
13 ms |
4436 KB |
Output is correct |
7 |
Correct |
13 ms |
4436 KB |
Output is correct |
8 |
Correct |
19 ms |
4436 KB |
Output is correct |
9 |
Correct |
12 ms |
4520 KB |
Output is correct |
10 |
Correct |
13 ms |
4560 KB |
Output is correct |
11 |
Correct |
22 ms |
4560 KB |
Output is correct |
12 |
Correct |
12 ms |
4560 KB |
Output is correct |
13 |
Correct |
13 ms |
4560 KB |
Output is correct |
14 |
Correct |
15 ms |
4560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
4560 KB |
Output is correct |
2 |
Correct |
13 ms |
4560 KB |
Output is correct |
3 |
Correct |
18 ms |
4560 KB |
Output is correct |
4 |
Correct |
11 ms |
4560 KB |
Output is correct |
5 |
Correct |
3 ms |
4560 KB |
Output is correct |
6 |
Correct |
7 ms |
4560 KB |
Output is correct |
7 |
Correct |
8 ms |
4560 KB |
Output is correct |
8 |
Correct |
9 ms |
4560 KB |
Output is correct |
9 |
Correct |
8 ms |
4560 KB |
Output is correct |
10 |
Correct |
5 ms |
4560 KB |
Output is correct |
11 |
Correct |
8 ms |
4560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1272 KB |
Output is correct |
2 |
Correct |
10 ms |
1272 KB |
Output is correct |
3 |
Correct |
13 ms |
1472 KB |
Output is correct |
4 |
Correct |
9 ms |
1472 KB |
Output is correct |
5 |
Correct |
10 ms |
1472 KB |
Output is correct |
6 |
Correct |
9 ms |
1472 KB |
Output is correct |
7 |
Correct |
8 ms |
1472 KB |
Output is correct |
8 |
Correct |
10 ms |
1484 KB |
Output is correct |
9 |
Correct |
8 ms |
1484 KB |
Output is correct |
10 |
Correct |
10 ms |
1484 KB |
Output is correct |
11 |
Correct |
8 ms |
1492 KB |
Output is correct |
12 |
Correct |
3 ms |
1492 KB |
Output is correct |
13 |
Correct |
3 ms |
1492 KB |
Output is correct |
14 |
Correct |
3 ms |
1492 KB |
Output is correct |
15 |
Correct |
2 ms |
1492 KB |
Output is correct |
16 |
Correct |
2 ms |
1492 KB |
Output is correct |
17 |
Correct |
3 ms |
1492 KB |
Output is correct |
18 |
Correct |
3 ms |
1492 KB |
Output is correct |
19 |
Correct |
3 ms |
1492 KB |
Output is correct |
20 |
Correct |
3 ms |
1492 KB |
Output is correct |
21 |
Correct |
4 ms |
1492 KB |
Output is correct |
22 |
Correct |
3 ms |
1492 KB |
Output is correct |
23 |
Correct |
2 ms |
1492 KB |
Output is correct |
24 |
Correct |
2 ms |
1492 KB |
Output is correct |
25 |
Correct |
3 ms |
1492 KB |
Output is correct |
26 |
Correct |
4 ms |
1492 KB |
Output is correct |
27 |
Correct |
2 ms |
1492 KB |
Output is correct |
28 |
Correct |
5 ms |
1492 KB |
Output is correct |
29 |
Correct |
3 ms |
1492 KB |
Output is correct |
30 |
Correct |
4 ms |
1492 KB |
Output is correct |
31 |
Correct |
4 ms |
1492 KB |
Output is correct |
32 |
Correct |
131 ms |
1996 KB |
Output is correct |
33 |
Correct |
258 ms |
1996 KB |
Output is correct |
34 |
Correct |
346 ms |
2020 KB |
Output is correct |
35 |
Correct |
14 ms |
2020 KB |
Output is correct |
36 |
Correct |
13 ms |
2020 KB |
Output is correct |
37 |
Correct |
15 ms |
2144 KB |
Output is correct |
38 |
Correct |
15 ms |
2344 KB |
Output is correct |
39 |
Correct |
15 ms |
2556 KB |
Output is correct |
40 |
Correct |
13 ms |
2764 KB |
Output is correct |
41 |
Correct |
16 ms |
2828 KB |
Output is correct |
42 |
Correct |
16 ms |
3076 KB |
Output is correct |
43 |
Correct |
13 ms |
3272 KB |
Output is correct |
44 |
Correct |
15 ms |
3528 KB |
Output is correct |
45 |
Correct |
12 ms |
3724 KB |
Output is correct |
46 |
Correct |
14 ms |
3944 KB |
Output is correct |
47 |
Correct |
13 ms |
4152 KB |
Output is correct |
48 |
Correct |
15 ms |
4360 KB |
Output is correct |
49 |
Correct |
525 ms |
4360 KB |
Output is correct |
50 |
Correct |
11 ms |
4360 KB |
Output is correct |
51 |
Correct |
13 ms |
4360 KB |
Output is correct |
52 |
Correct |
11 ms |
4432 KB |
Output is correct |
53 |
Correct |
19 ms |
4436 KB |
Output is correct |
54 |
Correct |
18 ms |
4436 KB |
Output is correct |
55 |
Correct |
13 ms |
4436 KB |
Output is correct |
56 |
Correct |
13 ms |
4436 KB |
Output is correct |
57 |
Correct |
19 ms |
4436 KB |
Output is correct |
58 |
Correct |
12 ms |
4520 KB |
Output is correct |
59 |
Correct |
13 ms |
4560 KB |
Output is correct |
60 |
Correct |
22 ms |
4560 KB |
Output is correct |
61 |
Correct |
12 ms |
4560 KB |
Output is correct |
62 |
Correct |
13 ms |
4560 KB |
Output is correct |
63 |
Correct |
15 ms |
4560 KB |
Output is correct |
64 |
Correct |
14 ms |
4560 KB |
Output is correct |
65 |
Correct |
13 ms |
4560 KB |
Output is correct |
66 |
Correct |
18 ms |
4560 KB |
Output is correct |
67 |
Correct |
11 ms |
4560 KB |
Output is correct |
68 |
Correct |
3 ms |
4560 KB |
Output is correct |
69 |
Correct |
7 ms |
4560 KB |
Output is correct |
70 |
Correct |
8 ms |
4560 KB |
Output is correct |
71 |
Correct |
9 ms |
4560 KB |
Output is correct |
72 |
Correct |
8 ms |
4560 KB |
Output is correct |
73 |
Correct |
5 ms |
4560 KB |
Output is correct |
74 |
Correct |
8 ms |
4560 KB |
Output is correct |
75 |
Correct |
176 ms |
4724 KB |
Output is correct |
76 |
Correct |
247 ms |
5020 KB |
Output is correct |
77 |
Correct |
352 ms |
5248 KB |
Output is correct |
78 |
Correct |
357 ms |
5412 KB |
Output is correct |
79 |
Correct |
399 ms |
5568 KB |
Output is correct |
80 |
Correct |
15 ms |
5728 KB |
Output is correct |
81 |
Correct |
14 ms |
5996 KB |
Output is correct |
82 |
Correct |
15 ms |
6096 KB |
Output is correct |
83 |
Correct |
19 ms |
6312 KB |
Output is correct |
84 |
Correct |
16 ms |
6512 KB |
Output is correct |
85 |
Correct |
15 ms |
6716 KB |
Output is correct |
86 |
Correct |
15 ms |
7036 KB |
Output is correct |
87 |
Correct |
13 ms |
7244 KB |
Output is correct |
88 |
Correct |
19 ms |
7452 KB |
Output is correct |
89 |
Correct |
18 ms |
7788 KB |
Output is correct |
90 |
Correct |
26 ms |
7868 KB |
Output is correct |
91 |
Correct |
22 ms |
8188 KB |
Output is correct |
92 |
Correct |
33 ms |
8404 KB |
Output is correct |
93 |
Correct |
33 ms |
8492 KB |
Output is correct |
94 |
Correct |
38 ms |
8700 KB |
Output is correct |
95 |
Correct |
39 ms |
8908 KB |
Output is correct |
96 |
Correct |
109 ms |
8988 KB |
Output is correct |
97 |
Correct |
407 ms |
9432 KB |
Output is correct |
98 |
Correct |
658 ms |
9500 KB |
Output is correct |
99 |
Correct |
708 ms |
9584 KB |
Output is correct |
100 |
Correct |
515 ms |
9660 KB |
Output is correct |