#include "train.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=30000+10;
vector<int>adj[maxn],revadj[maxn];
int n,shar[maxn],arez[maxn],m,dp[maxn],vas[maxn],dide[maxn],cn[maxn];
void bfs(){
vector<int>bf;
for(int i=0;i<n;i++){
vas[i]=0;
if(dp[i]==1){
bf.push_back(i);
}
cn[i]=0;
}
for(int u=0;u<(int)bf.size();u++){
for(auto x:revadj[bf[u]]){
cn[x]++;
}
for(auto i:revadj[bf[u]]){
if(dp[i]){
continue;
}
int cnt=cn[i];
int f=0;
// for(auto x:adj[i]){
// if(dp[x]==1){
// cnt++;
// }
// }
if(arez[i]){
if(cnt>0){
dp[i]=1;
bf.push_back(i);
}else{
dp[i]=0;
}
}else{
if(cnt!=(int)adj[i].size()){
dp[i]=0;
}else{
dp[i]=1;
bf.push_back(i);
}
}
}
}
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
n=(int)a.size();
m=(int)u.size();
for(int i=0;i<=n;i++){
adj[i].clear();
revadj[i].clear();
shar[i]=vas[i]=dide[i]=dp[i]=arez[i]=0;
}
for(int i=0;i<n;i++){
if(a[i]){
arez[i]=1;
}
if(r[i]){
shar[i]=1;
}
}
for(int i=0;i<m;i++){
revadj[v[i]].push_back(u[i]);
adj[u[i]].push_back(v[i]);
}
for(int nago=0;nago<=n;nago++){
for(int i=0;i<n;i++){
dp[i]=shar[i];
}
bfs();
/*for(int asd=0;asd<=n;asd++){
for(int i=0;i<n;i++){
if(dp[i]){
continue;
}
int cnt=0;
int f=0;
for(auto x:adj[i]){
if(dp[x]==1){
cnt++;
}
}
if(arez[i]){
if(cnt>0){
dp[i]=1;
}else{
dp[i]=0;
}
}else{
if(cnt!=(int)adj[i].size()){
dp[i]=0;
}else{
dp[i]=1;
}
}
}
}*/
if(nago!=n){
for(int i=0;i<n;i++){
if(shar[i]==1){
int cnt=0;
for(auto x:adj[i]){
if(dp[x]==1){
cnt++;
}
}
if(arez[i]){
shar[i]=(cnt>=1);
}else{
shar[i]=(cnt==(int)adj[i].size());
}
}
}
}
}
vector<int>res(n);
for(int i=0;i<n;i++){
res[i]=dp[i];
}
return res;
}
Compilation message
train.cpp: In function 'void bfs()':
train.cpp:26:8: warning: unused variable 'f' [-Wunused-variable]
26 | int f=0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
234 ms |
2396 KB |
Output is correct |
2 |
Correct |
221 ms |
2392 KB |
Output is correct |
3 |
Correct |
234 ms |
2396 KB |
Output is correct |
4 |
Correct |
226 ms |
2396 KB |
Output is correct |
5 |
Correct |
222 ms |
2392 KB |
Output is correct |
6 |
Correct |
224 ms |
2392 KB |
Output is correct |
7 |
Correct |
123 ms |
2396 KB |
Output is correct |
8 |
Correct |
332 ms |
2396 KB |
Output is correct |
9 |
Correct |
256 ms |
2468 KB |
Output is correct |
10 |
Correct |
213 ms |
2392 KB |
Output is correct |
11 |
Correct |
218 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1624 KB |
Output is correct |
2 |
Correct |
1 ms |
1628 KB |
Output is correct |
3 |
Correct |
1 ms |
1628 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1628 KB |
Output is correct |
7 |
Correct |
1 ms |
1624 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
1 ms |
1628 KB |
Output is correct |
13 |
Correct |
1 ms |
1628 KB |
Output is correct |
14 |
Correct |
1 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1628 KB |
Output is correct |
16 |
Correct |
1 ms |
1628 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
1 ms |
1628 KB |
Output is correct |
19 |
Correct |
1 ms |
1628 KB |
Output is correct |
20 |
Correct |
1 ms |
1624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
2900 KB |
Output is correct |
2 |
Correct |
149 ms |
2652 KB |
Output is correct |
3 |
Correct |
158 ms |
2860 KB |
Output is correct |
4 |
Correct |
857 ms |
2648 KB |
Output is correct |
5 |
Correct |
357 ms |
2904 KB |
Output is correct |
6 |
Correct |
94 ms |
2648 KB |
Output is correct |
7 |
Correct |
884 ms |
2820 KB |
Output is correct |
8 |
Correct |
265 ms |
2648 KB |
Output is correct |
9 |
Correct |
87 ms |
2740 KB |
Output is correct |
10 |
Correct |
328 ms |
2648 KB |
Output is correct |
11 |
Correct |
259 ms |
2648 KB |
Output is correct |
12 |
Correct |
91 ms |
2900 KB |
Output is correct |
13 |
Correct |
776 ms |
2832 KB |
Output is correct |
14 |
Correct |
788 ms |
2648 KB |
Output is correct |
15 |
Correct |
803 ms |
2652 KB |
Output is correct |
16 |
Correct |
756 ms |
2828 KB |
Output is correct |
17 |
Correct |
761 ms |
2836 KB |
Output is correct |
18 |
Correct |
191 ms |
2568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
660 ms |
2676 KB |
Output is correct |
2 |
Correct |
496 ms |
2648 KB |
Output is correct |
3 |
Correct |
114 ms |
2648 KB |
Output is correct |
4 |
Correct |
87 ms |
2652 KB |
Output is correct |
5 |
Correct |
396 ms |
2796 KB |
Output is correct |
6 |
Correct |
573 ms |
2896 KB |
Output is correct |
7 |
Correct |
519 ms |
2652 KB |
Output is correct |
8 |
Correct |
107 ms |
2652 KB |
Output is correct |
9 |
Correct |
774 ms |
2648 KB |
Output is correct |
10 |
Correct |
1124 ms |
2652 KB |
Output is correct |
11 |
Correct |
858 ms |
2648 KB |
Output is correct |
12 |
Correct |
1233 ms |
2832 KB |
Output is correct |
13 |
Correct |
494 ms |
2800 KB |
Output is correct |
14 |
Correct |
629 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
468 ms |
2808 KB |
Output is correct |
2 |
Correct |
1131 ms |
2828 KB |
Output is correct |
3 |
Correct |
1029 ms |
2808 KB |
Output is correct |
4 |
Correct |
1161 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
1884 KB |
Output is correct |
6 |
Correct |
85 ms |
2416 KB |
Output is correct |
7 |
Correct |
19 ms |
2392 KB |
Output is correct |
8 |
Correct |
4 ms |
2396 KB |
Output is correct |
9 |
Correct |
16 ms |
2624 KB |
Output is correct |
10 |
Correct |
4 ms |
2140 KB |
Output is correct |
11 |
Correct |
29 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
234 ms |
2396 KB |
Output is correct |
2 |
Correct |
221 ms |
2392 KB |
Output is correct |
3 |
Correct |
234 ms |
2396 KB |
Output is correct |
4 |
Correct |
226 ms |
2396 KB |
Output is correct |
5 |
Correct |
222 ms |
2392 KB |
Output is correct |
6 |
Correct |
224 ms |
2392 KB |
Output is correct |
7 |
Correct |
123 ms |
2396 KB |
Output is correct |
8 |
Correct |
332 ms |
2396 KB |
Output is correct |
9 |
Correct |
256 ms |
2468 KB |
Output is correct |
10 |
Correct |
213 ms |
2392 KB |
Output is correct |
11 |
Correct |
218 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
1624 KB |
Output is correct |
13 |
Correct |
1 ms |
1628 KB |
Output is correct |
14 |
Correct |
1 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1628 KB |
Output is correct |
16 |
Correct |
1 ms |
1628 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
1 ms |
1624 KB |
Output is correct |
19 |
Correct |
1 ms |
1628 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
21 |
Correct |
1 ms |
1628 KB |
Output is correct |
22 |
Correct |
1 ms |
1628 KB |
Output is correct |
23 |
Correct |
1 ms |
1628 KB |
Output is correct |
24 |
Correct |
1 ms |
1628 KB |
Output is correct |
25 |
Correct |
1 ms |
1628 KB |
Output is correct |
26 |
Correct |
1 ms |
1628 KB |
Output is correct |
27 |
Correct |
1 ms |
1628 KB |
Output is correct |
28 |
Correct |
1 ms |
1628 KB |
Output is correct |
29 |
Correct |
1 ms |
1628 KB |
Output is correct |
30 |
Correct |
1 ms |
1628 KB |
Output is correct |
31 |
Correct |
1 ms |
1624 KB |
Output is correct |
32 |
Correct |
127 ms |
2900 KB |
Output is correct |
33 |
Correct |
149 ms |
2652 KB |
Output is correct |
34 |
Correct |
158 ms |
2860 KB |
Output is correct |
35 |
Correct |
857 ms |
2648 KB |
Output is correct |
36 |
Correct |
357 ms |
2904 KB |
Output is correct |
37 |
Correct |
94 ms |
2648 KB |
Output is correct |
38 |
Correct |
884 ms |
2820 KB |
Output is correct |
39 |
Correct |
265 ms |
2648 KB |
Output is correct |
40 |
Correct |
87 ms |
2740 KB |
Output is correct |
41 |
Correct |
328 ms |
2648 KB |
Output is correct |
42 |
Correct |
259 ms |
2648 KB |
Output is correct |
43 |
Correct |
91 ms |
2900 KB |
Output is correct |
44 |
Correct |
776 ms |
2832 KB |
Output is correct |
45 |
Correct |
788 ms |
2648 KB |
Output is correct |
46 |
Correct |
803 ms |
2652 KB |
Output is correct |
47 |
Correct |
756 ms |
2828 KB |
Output is correct |
48 |
Correct |
761 ms |
2836 KB |
Output is correct |
49 |
Correct |
191 ms |
2568 KB |
Output is correct |
50 |
Correct |
660 ms |
2676 KB |
Output is correct |
51 |
Correct |
496 ms |
2648 KB |
Output is correct |
52 |
Correct |
114 ms |
2648 KB |
Output is correct |
53 |
Correct |
87 ms |
2652 KB |
Output is correct |
54 |
Correct |
396 ms |
2796 KB |
Output is correct |
55 |
Correct |
573 ms |
2896 KB |
Output is correct |
56 |
Correct |
519 ms |
2652 KB |
Output is correct |
57 |
Correct |
107 ms |
2652 KB |
Output is correct |
58 |
Correct |
774 ms |
2648 KB |
Output is correct |
59 |
Correct |
1124 ms |
2652 KB |
Output is correct |
60 |
Correct |
858 ms |
2648 KB |
Output is correct |
61 |
Correct |
1233 ms |
2832 KB |
Output is correct |
62 |
Correct |
494 ms |
2800 KB |
Output is correct |
63 |
Correct |
629 ms |
2652 KB |
Output is correct |
64 |
Correct |
468 ms |
2808 KB |
Output is correct |
65 |
Correct |
1131 ms |
2828 KB |
Output is correct |
66 |
Correct |
1029 ms |
2808 KB |
Output is correct |
67 |
Correct |
1161 ms |
2652 KB |
Output is correct |
68 |
Correct |
1 ms |
1884 KB |
Output is correct |
69 |
Correct |
85 ms |
2416 KB |
Output is correct |
70 |
Correct |
19 ms |
2392 KB |
Output is correct |
71 |
Correct |
4 ms |
2396 KB |
Output is correct |
72 |
Correct |
16 ms |
2624 KB |
Output is correct |
73 |
Correct |
4 ms |
2140 KB |
Output is correct |
74 |
Correct |
29 ms |
2396 KB |
Output is correct |
75 |
Correct |
139 ms |
3048 KB |
Output is correct |
76 |
Correct |
164 ms |
2904 KB |
Output is correct |
77 |
Correct |
172 ms |
2904 KB |
Output is correct |
78 |
Correct |
174 ms |
2908 KB |
Output is correct |
79 |
Correct |
174 ms |
3068 KB |
Output is correct |
80 |
Correct |
1292 ms |
3040 KB |
Output is correct |
81 |
Correct |
263 ms |
2888 KB |
Output is correct |
82 |
Correct |
403 ms |
3004 KB |
Output is correct |
83 |
Correct |
364 ms |
2904 KB |
Output is correct |
84 |
Correct |
291 ms |
2904 KB |
Output is correct |
85 |
Correct |
98 ms |
3000 KB |
Output is correct |
86 |
Correct |
246 ms |
3032 KB |
Output is correct |
87 |
Correct |
96 ms |
3000 KB |
Output is correct |
88 |
Correct |
174 ms |
2908 KB |
Output is correct |
89 |
Correct |
340 ms |
2908 KB |
Output is correct |
90 |
Correct |
98 ms |
2904 KB |
Output is correct |
91 |
Correct |
122 ms |
2908 KB |
Output is correct |
92 |
Correct |
252 ms |
3040 KB |
Output is correct |
93 |
Correct |
245 ms |
3036 KB |
Output is correct |
94 |
Correct |
171 ms |
2904 KB |
Output is correct |
95 |
Correct |
267 ms |
2908 KB |
Output is correct |
96 |
Correct |
548 ms |
2908 KB |
Output is correct |
97 |
Correct |
225 ms |
2904 KB |
Output is correct |
98 |
Correct |
283 ms |
3016 KB |
Output is correct |
99 |
Correct |
237 ms |
2904 KB |
Output is correct |
100 |
Correct |
186 ms |
2648 KB |
Output is correct |