#include "game.h"
#include <bits/stdc++.h>
using namespace std;
int n , k;
vector< int > mx , mn , l , r;
vector< vector< int > > g , g2;
bool fixNode(int node){
if(mx[node] >= mn[node])
return false;
int mid;
bool good = false;
while(l[node] < r[node]){
mid = (l[node] + r[node]) / 2;
if(mn[node] <= mid){
r[node] = mid;
good = true;
}
else if(mx[node] > mid){
l[node] = mid + 1;
good = true;
}
else
break;
}
return good;
}
void init(int n, int k) {
::n = n;
::k = k;
mx.resize(n , 0);
mn.resize(n , k + 1);
l.resize(n , 0);
r.resize(n , k + 1);
for(int i = 0 ;i < k;i++){
mn[i] = mx[i] = i + 1;
}
g.resize(n);
g2.resize(n);
}
void DFSMax(int node){
for(int i = 0 ;i < (int)g[node].size();i++){
if(g[node][i] < k){
mn[node] = min(mn[node] , g[node][i] + 1);
continue;
}
mx[g[node][i]] = max(mx[g[node][i]] , mx[node]);
if(fixNode(g[node][i])){
DFSMax(g[node][i]);
}
mn[node] = min(mn[node] , mn[g[node][i]]);
}
fixNode(node);
}
void DFSMin(int node){
for(int i = 0 ;i < (int)g2[node].size();i++){
if(g2[node][i] < k){
mx[node] = max(mx[node] , g2[node][i] + 1);
continue;
}
mn[g2[node][i]] = min(mn[g2[node][i]] , mn[node]);
if(fixNode(g2[node][i])){
DFSMin(g2[node][i]);
}
mx[node] = max(mx[node] , mx[g2[node][i]]);
}
fixNode(node);
}
int add_teleporter(int u, int v) {
if(u < k && v < k){
if(u >= v)
return 1;
return 0;
}
g[u].push_back(v);
g2[v].push_back(u);
//fix max
if(v >= k){
mx[v] = max(mx[v] , mx[u]);
if(fixNode(v)){
DFSMax(v);
DFSMin(v);
}
if(mx[v] >= mn[v])
return 1;
}
//fix min
if(u >= k){
mn[u] = min(mn[u] , mn[v]);
if(fixNode(u)){
DFSMin(u);
DFSMax(u);
}
if(mx[u] >= mn[u])
return 1;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
0 ms |
208 KB |
Output is correct |
15 |
Correct |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
0 ms |
208 KB |
Output is correct |
15 |
Correct |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
0 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
464 KB |
Output is correct |
26 |
Correct |
3 ms |
432 KB |
Output is correct |
27 |
Correct |
3 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
0 ms |
208 KB |
Output is correct |
15 |
Correct |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
0 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
464 KB |
Output is correct |
26 |
Correct |
3 ms |
432 KB |
Output is correct |
27 |
Correct |
3 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
25 ms |
3260 KB |
Output is correct |
31 |
Correct |
6 ms |
2512 KB |
Output is correct |
32 |
Correct |
19 ms |
5212 KB |
Output is correct |
33 |
Correct |
18 ms |
4040 KB |
Output is correct |
34 |
Correct |
29 ms |
6212 KB |
Output is correct |
35 |
Correct |
40 ms |
4764 KB |
Output is correct |
36 |
Correct |
38 ms |
3964 KB |
Output is correct |
37 |
Correct |
33 ms |
4040 KB |
Output is correct |
38 |
Correct |
31 ms |
3784 KB |
Output is correct |
39 |
Correct |
27 ms |
3736 KB |
Output is correct |
40 |
Correct |
31 ms |
6208 KB |
Output is correct |
41 |
Correct |
35 ms |
4384 KB |
Output is correct |
42 |
Correct |
29 ms |
4124 KB |
Output is correct |
43 |
Correct |
40 ms |
5260 KB |
Output is correct |
44 |
Correct |
42 ms |
4636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
0 ms |
208 KB |
Output is correct |
15 |
Correct |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
0 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
0 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
464 KB |
Output is correct |
26 |
Correct |
3 ms |
432 KB |
Output is correct |
27 |
Correct |
3 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
25 ms |
3260 KB |
Output is correct |
31 |
Correct |
6 ms |
2512 KB |
Output is correct |
32 |
Correct |
19 ms |
5212 KB |
Output is correct |
33 |
Correct |
18 ms |
4040 KB |
Output is correct |
34 |
Correct |
29 ms |
6212 KB |
Output is correct |
35 |
Correct |
40 ms |
4764 KB |
Output is correct |
36 |
Correct |
38 ms |
3964 KB |
Output is correct |
37 |
Correct |
33 ms |
4040 KB |
Output is correct |
38 |
Correct |
31 ms |
3784 KB |
Output is correct |
39 |
Correct |
27 ms |
3736 KB |
Output is correct |
40 |
Correct |
31 ms |
6208 KB |
Output is correct |
41 |
Correct |
35 ms |
4384 KB |
Output is correct |
42 |
Correct |
29 ms |
4124 KB |
Output is correct |
43 |
Correct |
40 ms |
5260 KB |
Output is correct |
44 |
Correct |
42 ms |
4636 KB |
Output is correct |
45 |
Correct |
267 ms |
30476 KB |
Output is correct |
46 |
Correct |
15 ms |
19536 KB |
Output is correct |
47 |
Correct |
16 ms |
19392 KB |
Output is correct |
48 |
Correct |
374 ms |
47932 KB |
Output is correct |
49 |
Correct |
289 ms |
37900 KB |
Output is correct |
50 |
Correct |
382 ms |
45584 KB |
Output is correct |
51 |
Correct |
653 ms |
43332 KB |
Output is correct |
52 |
Correct |
603 ms |
37832 KB |
Output is correct |
53 |
Correct |
701 ms |
37884 KB |
Output is correct |
54 |
Correct |
791 ms |
37784 KB |
Output is correct |
55 |
Correct |
975 ms |
38208 KB |
Output is correct |
56 |
Correct |
1195 ms |
37936 KB |
Output is correct |
57 |
Correct |
454 ms |
31768 KB |
Output is correct |
58 |
Correct |
506 ms |
32100 KB |
Output is correct |
59 |
Correct |
492 ms |
32084 KB |
Output is correct |
60 |
Correct |
547 ms |
31720 KB |
Output is correct |
61 |
Correct |
567 ms |
31428 KB |
Output is correct |
62 |
Correct |
400 ms |
38280 KB |
Output is correct |
63 |
Correct |
301 ms |
34932 KB |
Output is correct |
64 |
Correct |
863 ms |
54740 KB |
Output is correct |
65 |
Correct |
471 ms |
36768 KB |
Output is correct |
66 |
Correct |
397 ms |
32600 KB |
Output is correct |
67 |
Correct |
711 ms |
41372 KB |
Output is correct |
68 |
Correct |
252 ms |
28528 KB |
Output is correct |
69 |
Correct |
75 ms |
22544 KB |
Output is correct |
70 |
Correct |
716 ms |
39844 KB |
Output is correct |
71 |
Correct |
352 ms |
30612 KB |
Output is correct |
72 |
Correct |
271 ms |
26368 KB |
Output is correct |
73 |
Correct |
630 ms |
37748 KB |
Output is correct |
74 |
Correct |
1398 ms |
37596 KB |
Output is correct |
75 |
Correct |
970 ms |
49720 KB |
Output is correct |
76 |
Correct |
1002 ms |
47676 KB |
Output is correct |