/**
* user: ppavic
* fname: Patrik
* lname: Pavić
* task: train
* score: 100.0
* date: 2019-06-12 09:27:16.425930
*/
#include "train.h"
#include <vector>
#include <cstring>
#include <queue>
#define PB push_back
using namespace std;
typedef vector < int > vi;
const int N = 5055;
int spas[N]; /// HDZ
int smrt[N]; /// SDP
int n;
vi v[N], r[N];
int cnt[N], izb[N];
queue < int > Q;
vi who_wins(vi a, vi rr, vi uu, vi vv) {
n = a.size();
for(int i = 0;i < (int)vv.size();i++){
v[uu[i]].PB(vv[i]);
r[vv[i]].PB(uu[i]);
}
int kol = 0;
for(;;kol++){
memset(spas, 0, sizeof(spas));
memset(smrt, 0, sizeof(smrt));
memset(cnt, 0, sizeof(cnt));
for(int i = 0;i < n;i++){
if(izb[i]) continue;
if(rr[i] == 1) smrt[i] = 1, Q.push(i);
else if(a[i] == 1) cnt[i] = 1;
else {
cnt[i] = 0;
for(int x : v[i])
cnt[i] += !izb[x];
}
}
for(;!Q.empty();Q.pop()){
int cur = Q.front();
for(int x : r[cur]){
if(izb[x]) continue;
cnt[x]--;
if(cnt[x] == 0 && !smrt[x]){
smrt[x] = 1;
Q.push(x);
}
}
}
for(int i = 0;i < n;i++){
if(izb[i]) continue;
if(smrt[i] == 0) spas[i] = 1, Q.push(i), cnt[i] = 0;
else if(a[i] == 0) cnt[i] = 1;
else {
cnt[i] = 0;
for(int x : v[i])
cnt[i] += !izb[x];
}
}
for(;!Q.empty();Q.pop()){
int cur = Q.front();
for(int x : r[cur]){
if(izb[x]) continue;
cnt[x]--;
if(cnt[x] == 0 && !spas[x]){
spas[x] = 1;
Q.push(x);
}
}
}
int cc = 0;
for(int i = 0;i < n;i++)
if(spas[i] && !izb[i]) cc++, izb[i] = 1;
if(cc == 0) break;
}
vi sol;
for(int i = 0;i < n;i++)
sol.PB(!izb[i]);
return sol;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1280 KB |
Output is correct |
2 |
Correct |
10 ms |
1280 KB |
Output is correct |
3 |
Correct |
10 ms |
1280 KB |
Output is correct |
4 |
Correct |
10 ms |
1280 KB |
Output is correct |
5 |
Correct |
10 ms |
1280 KB |
Output is correct |
6 |
Correct |
9 ms |
1280 KB |
Output is correct |
7 |
Correct |
9 ms |
1280 KB |
Output is correct |
8 |
Correct |
10 ms |
1280 KB |
Output is correct |
9 |
Correct |
12 ms |
1536 KB |
Output is correct |
10 |
Correct |
9 ms |
1280 KB |
Output is correct |
11 |
Correct |
9 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
7 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
6 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
640 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
1788 KB |
Output is correct |
2 |
Correct |
226 ms |
1788 KB |
Output is correct |
3 |
Correct |
319 ms |
1784 KB |
Output is correct |
4 |
Correct |
14 ms |
1664 KB |
Output is correct |
5 |
Correct |
15 ms |
1664 KB |
Output is correct |
6 |
Correct |
18 ms |
1664 KB |
Output is correct |
7 |
Correct |
14 ms |
1664 KB |
Output is correct |
8 |
Correct |
14 ms |
1664 KB |
Output is correct |
9 |
Correct |
13 ms |
1664 KB |
Output is correct |
10 |
Correct |
15 ms |
1664 KB |
Output is correct |
11 |
Correct |
13 ms |
1664 KB |
Output is correct |
12 |
Correct |
12 ms |
1664 KB |
Output is correct |
13 |
Correct |
13 ms |
1664 KB |
Output is correct |
14 |
Correct |
15 ms |
1664 KB |
Output is correct |
15 |
Correct |
14 ms |
1664 KB |
Output is correct |
16 |
Correct |
14 ms |
1664 KB |
Output is correct |
17 |
Correct |
14 ms |
1664 KB |
Output is correct |
18 |
Correct |
362 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1536 KB |
Output is correct |
2 |
Correct |
13 ms |
1536 KB |
Output is correct |
3 |
Correct |
14 ms |
1664 KB |
Output is correct |
4 |
Correct |
15 ms |
1664 KB |
Output is correct |
5 |
Correct |
19 ms |
1660 KB |
Output is correct |
6 |
Correct |
14 ms |
1664 KB |
Output is correct |
7 |
Correct |
14 ms |
1664 KB |
Output is correct |
8 |
Correct |
13 ms |
1664 KB |
Output is correct |
9 |
Correct |
13 ms |
1536 KB |
Output is correct |
10 |
Correct |
13 ms |
1664 KB |
Output is correct |
11 |
Correct |
14 ms |
1664 KB |
Output is correct |
12 |
Correct |
15 ms |
1664 KB |
Output is correct |
13 |
Correct |
14 ms |
1664 KB |
Output is correct |
14 |
Correct |
14 ms |
1664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1664 KB |
Output is correct |
2 |
Correct |
14 ms |
1664 KB |
Output is correct |
3 |
Correct |
18 ms |
1664 KB |
Output is correct |
4 |
Correct |
13 ms |
1536 KB |
Output is correct |
5 |
Correct |
5 ms |
768 KB |
Output is correct |
6 |
Correct |
9 ms |
1280 KB |
Output is correct |
7 |
Correct |
10 ms |
1280 KB |
Output is correct |
8 |
Correct |
10 ms |
1408 KB |
Output is correct |
9 |
Correct |
10 ms |
1280 KB |
Output is correct |
10 |
Correct |
7 ms |
768 KB |
Output is correct |
11 |
Correct |
10 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1280 KB |
Output is correct |
2 |
Correct |
10 ms |
1280 KB |
Output is correct |
3 |
Correct |
10 ms |
1280 KB |
Output is correct |
4 |
Correct |
10 ms |
1280 KB |
Output is correct |
5 |
Correct |
10 ms |
1280 KB |
Output is correct |
6 |
Correct |
9 ms |
1280 KB |
Output is correct |
7 |
Correct |
9 ms |
1280 KB |
Output is correct |
8 |
Correct |
10 ms |
1280 KB |
Output is correct |
9 |
Correct |
12 ms |
1536 KB |
Output is correct |
10 |
Correct |
9 ms |
1280 KB |
Output is correct |
11 |
Correct |
9 ms |
1152 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
6 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
640 KB |
Output is correct |
16 |
Correct |
7 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
18 |
Correct |
5 ms |
640 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
640 KB |
Output is correct |
21 |
Correct |
5 ms |
640 KB |
Output is correct |
22 |
Correct |
5 ms |
640 KB |
Output is correct |
23 |
Correct |
5 ms |
640 KB |
Output is correct |
24 |
Correct |
5 ms |
640 KB |
Output is correct |
25 |
Correct |
6 ms |
640 KB |
Output is correct |
26 |
Correct |
5 ms |
640 KB |
Output is correct |
27 |
Correct |
5 ms |
640 KB |
Output is correct |
28 |
Correct |
5 ms |
640 KB |
Output is correct |
29 |
Correct |
5 ms |
640 KB |
Output is correct |
30 |
Correct |
5 ms |
640 KB |
Output is correct |
31 |
Correct |
5 ms |
640 KB |
Output is correct |
32 |
Correct |
125 ms |
1788 KB |
Output is correct |
33 |
Correct |
226 ms |
1788 KB |
Output is correct |
34 |
Correct |
319 ms |
1784 KB |
Output is correct |
35 |
Correct |
14 ms |
1664 KB |
Output is correct |
36 |
Correct |
15 ms |
1664 KB |
Output is correct |
37 |
Correct |
18 ms |
1664 KB |
Output is correct |
38 |
Correct |
14 ms |
1664 KB |
Output is correct |
39 |
Correct |
14 ms |
1664 KB |
Output is correct |
40 |
Correct |
13 ms |
1664 KB |
Output is correct |
41 |
Correct |
15 ms |
1664 KB |
Output is correct |
42 |
Correct |
13 ms |
1664 KB |
Output is correct |
43 |
Correct |
12 ms |
1664 KB |
Output is correct |
44 |
Correct |
13 ms |
1664 KB |
Output is correct |
45 |
Correct |
15 ms |
1664 KB |
Output is correct |
46 |
Correct |
14 ms |
1664 KB |
Output is correct |
47 |
Correct |
14 ms |
1664 KB |
Output is correct |
48 |
Correct |
14 ms |
1664 KB |
Output is correct |
49 |
Correct |
362 ms |
1400 KB |
Output is correct |
50 |
Correct |
12 ms |
1536 KB |
Output is correct |
51 |
Correct |
13 ms |
1536 KB |
Output is correct |
52 |
Correct |
14 ms |
1664 KB |
Output is correct |
53 |
Correct |
15 ms |
1664 KB |
Output is correct |
54 |
Correct |
19 ms |
1660 KB |
Output is correct |
55 |
Correct |
14 ms |
1664 KB |
Output is correct |
56 |
Correct |
14 ms |
1664 KB |
Output is correct |
57 |
Correct |
13 ms |
1664 KB |
Output is correct |
58 |
Correct |
13 ms |
1536 KB |
Output is correct |
59 |
Correct |
13 ms |
1664 KB |
Output is correct |
60 |
Correct |
14 ms |
1664 KB |
Output is correct |
61 |
Correct |
15 ms |
1664 KB |
Output is correct |
62 |
Correct |
14 ms |
1664 KB |
Output is correct |
63 |
Correct |
14 ms |
1664 KB |
Output is correct |
64 |
Correct |
14 ms |
1664 KB |
Output is correct |
65 |
Correct |
14 ms |
1664 KB |
Output is correct |
66 |
Correct |
18 ms |
1664 KB |
Output is correct |
67 |
Correct |
13 ms |
1536 KB |
Output is correct |
68 |
Correct |
5 ms |
768 KB |
Output is correct |
69 |
Correct |
9 ms |
1280 KB |
Output is correct |
70 |
Correct |
10 ms |
1280 KB |
Output is correct |
71 |
Correct |
10 ms |
1408 KB |
Output is correct |
72 |
Correct |
10 ms |
1280 KB |
Output is correct |
73 |
Correct |
7 ms |
768 KB |
Output is correct |
74 |
Correct |
10 ms |
1280 KB |
Output is correct |
75 |
Correct |
166 ms |
1664 KB |
Output is correct |
76 |
Correct |
232 ms |
1784 KB |
Output is correct |
77 |
Correct |
322 ms |
1784 KB |
Output is correct |
78 |
Correct |
313 ms |
1784 KB |
Output is correct |
79 |
Correct |
318 ms |
1784 KB |
Output is correct |
80 |
Correct |
14 ms |
1664 KB |
Output is correct |
81 |
Correct |
14 ms |
1792 KB |
Output is correct |
82 |
Correct |
15 ms |
1664 KB |
Output is correct |
83 |
Correct |
14 ms |
1792 KB |
Output is correct |
84 |
Correct |
15 ms |
1664 KB |
Output is correct |
85 |
Correct |
14 ms |
1664 KB |
Output is correct |
86 |
Correct |
15 ms |
1792 KB |
Output is correct |
87 |
Correct |
14 ms |
1664 KB |
Output is correct |
88 |
Correct |
17 ms |
1792 KB |
Output is correct |
89 |
Correct |
17 ms |
1664 KB |
Output is correct |
90 |
Correct |
20 ms |
1792 KB |
Output is correct |
91 |
Correct |
19 ms |
1792 KB |
Output is correct |
92 |
Correct |
28 ms |
1664 KB |
Output is correct |
93 |
Correct |
28 ms |
1664 KB |
Output is correct |
94 |
Correct |
28 ms |
1664 KB |
Output is correct |
95 |
Correct |
29 ms |
1664 KB |
Output is correct |
96 |
Correct |
89 ms |
1656 KB |
Output is correct |
97 |
Correct |
310 ms |
1664 KB |
Output is correct |
98 |
Correct |
483 ms |
1664 KB |
Output is correct |
99 |
Correct |
494 ms |
1664 KB |
Output is correct |
100 |
Correct |
380 ms |
1400 KB |
Output is correct |