#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pll;
#define pb push_back
#define eb emplace_back
const int INF = 1e9;
#include "Anthony.h"
vector<int> Mark(int n, int m, int a, int b, vector<int> u, vector<int> v){
vector<vector<pll>> adj(n);
vector<int> dist(n, INF), deg(n);
dist[0] = 0;
for(int i = 0; i < m; i++){
adj[u[i]].eb(v[i], i);
adj[v[i]].eb(u[i], i);
deg[u[i]] ++, deg[v[i]] ++;
}
vector<int> color(m, -1);
vector<int> bd(n);
bd[0] = 0;
queue<pll> q;
q.push({0, 0});
if(a >= 3){
while(!q.empty()){
auto [pos, lst] = q.front(); q.pop();
for(auto [x, id] : adj[pos]){
if(color[id] != -1) continue;
if(dist[x] != INF){
if(dist[x] >= dist[pos]) color[id] = (lst + 1) % a;
else color[id] = lst;
continue;
}
// cout<<"do : "<<pos<<" "<<x<<" "<<lst<<"\n";
dist[x] = dist[pos] + 1;
color[id] = (lst + 1) % a;
q.push({x, color[id]});
}
}
// cout<<"dist : ";
// for(auto x : dist) cout<<x<<" ";
// cout<<"\n";
}
else{
string ck = "121221";
while(!q.empty()){
auto [pos, lst] = q.front(); q.pop();
int put;
if(deg[pos] > 2){
if(ck[lst] == '1') put = 1;
else put = 0;
}
else put = (lst + 1) % 6;
for(auto [x, id] : adj[pos]){
if(dist[x] != INF) continue;
dist[x] = dist[pos] + 1;
color[id] = (ck[put] - '1');
q.push({x, put});
}
}
}
return color;
}
// signed main(void){
// int n, m, a, b, s;
// cin>>n>>m>>a>>b>>s;
// vector<int> u(m), v(m);
// for(int i = 0; i < m; i++) cin>>u[i]>>v[i];
// auto c = Mark(n, m, a, b, u, v);
// for(auto x : c) cout<<x<<" ";
// cout<<"\n";
// }
#include "Catherine.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
int A, B, lst = -1, ok = 0;
string ck = "";
string s = "010110010110";
void Init(int a, int b){
A = a, B = b;
}
int find_dir(){
for(int i = 0; i < 6; i++){
int dif = 0;
for(int j = 0; j < 5; j++) if(ck[j] != s[i + j]){
dif = 1;
break;
}
if(!dif) return 1;
}
return 0;
}
int Move(vector<int> y){
// cout<<"ck : "<<A<<" "<<B<<"\n";
if(lst != -1) y[lst]++;
int deg = 0;
for(auto x : y) deg += (x != 0);
if(A >= 3){
if(deg == 1){
return max_element(y.begin(), y.end()) - y.begin();
}
for(int i = 0; i < A; i++){
// cout<<"try : "<<i<<" "<<y[i]<<" "<<y[(i + 1) % A]<<"\n";
if(y[i] && y[(i + 1) % A]){
return i;
}
}
}
// a = 2
deg = accumulate(y.begin(), y.end(), 0);
// cout<<"deg : "<<deg<<"\n";
if(deg == 1){
// cout<<"nothing, back\n";
ok = 1;
if(lst == -1){
lst = (y[0] == 0);
return lst;
}
else return -1;
}
if(deg > 2){
ok = 1;
if(y[0] == 1){
int tmp = lst;
lst = 0;
if(tmp == 0) return -1;
return 0;
}
else{
int tmp = lst;
lst = 1;
if(tmp == 1) return -1;
return 1;
}
}
// deg = 2
if(ok){
y[lst]--;
if(y[0]){
lst = 0;
return 0;
}
lst = 1;
return 1;
}
auto rot = [&]() -> int {
int d = find_dir();
// cout<<"end, change dir : "<<d<<"\n";
ok = 1;
if(d){
return -1;
}
if(y[0]){
lst = 0;
return 0;
}
else{
lst = 1;
return 1;
}
};
if(lst == -1){
if(y[0] == 2){
ck += "00", lst = 0;
return 0;
}
else if(y[1] == 2){
ck += "11", lst = 1;
return 1;
}
else{
ck += "01", lst = 1;
return 1;
}
}
else{
y[lst] --;
if(y[0]){
ck += '0';
if(ck.size() == 5) return rot();
lst = 0;
return 0;
}
else{
ck += '1';
if(ck.size() == 5) return rot();
lst = 1;
return 1;
}
}
}
/*
16 15 2 6 11
0 1
1 2
2 3
3 4
4 8
2 5
5 6
6 7
7 9
6 10
10 11
11 12
12 13
13 14
13 15
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
15324 KB |
Output is correct |
2 |
Correct |
0 ms |
780 KB |
Output is correct |
3 |
Correct |
25 ms |
14964 KB |
Output is correct |
4 |
Correct |
38 ms |
16408 KB |
Output is correct |
5 |
Correct |
36 ms |
16512 KB |
Output is correct |
6 |
Correct |
33 ms |
15320 KB |
Output is correct |
7 |
Correct |
38 ms |
15200 KB |
Output is correct |
8 |
Correct |
33 ms |
15868 KB |
Output is correct |
9 |
Correct |
35 ms |
16000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
15324 KB |
Output is correct |
2 |
Correct |
0 ms |
780 KB |
Output is correct |
3 |
Correct |
25 ms |
14964 KB |
Output is correct |
4 |
Correct |
38 ms |
16408 KB |
Output is correct |
5 |
Correct |
36 ms |
16512 KB |
Output is correct |
6 |
Correct |
33 ms |
15320 KB |
Output is correct |
7 |
Correct |
38 ms |
15200 KB |
Output is correct |
8 |
Correct |
33 ms |
15868 KB |
Output is correct |
9 |
Correct |
35 ms |
16000 KB |
Output is correct |
10 |
Correct |
27 ms |
13428 KB |
Output is correct |
11 |
Correct |
28 ms |
13384 KB |
Output is correct |
12 |
Correct |
31 ms |
13328 KB |
Output is correct |
13 |
Correct |
26 ms |
13232 KB |
Output is correct |
14 |
Correct |
28 ms |
13536 KB |
Output is correct |
15 |
Correct |
37 ms |
13712 KB |
Output is correct |
16 |
Correct |
34 ms |
16016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
12920 KB |
Output is correct |
2 |
Correct |
0 ms |
776 KB |
Output is correct |
3 |
Correct |
26 ms |
12876 KB |
Output is correct |
4 |
Correct |
44 ms |
14348 KB |
Output is correct |
5 |
Correct |
37 ms |
14304 KB |
Output is correct |
6 |
Correct |
26 ms |
13216 KB |
Output is correct |
7 |
Correct |
28 ms |
12952 KB |
Output is correct |
8 |
Correct |
34 ms |
13604 KB |
Output is correct |
9 |
Correct |
33 ms |
13812 KB |
Output is correct |
10 |
Correct |
32 ms |
13436 KB |
Output is correct |
11 |
Correct |
34 ms |
13556 KB |
Output is correct |
12 |
Correct |
36 ms |
13244 KB |
Output is correct |
13 |
Correct |
35 ms |
13600 KB |
Output is correct |
14 |
Correct |
33 ms |
13664 KB |
Output is correct |
15 |
Correct |
38 ms |
13504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
12920 KB |
Output is correct |
2 |
Correct |
0 ms |
776 KB |
Output is correct |
3 |
Correct |
26 ms |
12876 KB |
Output is correct |
4 |
Correct |
44 ms |
14348 KB |
Output is correct |
5 |
Correct |
37 ms |
14304 KB |
Output is correct |
6 |
Correct |
26 ms |
13216 KB |
Output is correct |
7 |
Correct |
28 ms |
12952 KB |
Output is correct |
8 |
Correct |
34 ms |
13604 KB |
Output is correct |
9 |
Correct |
33 ms |
13812 KB |
Output is correct |
10 |
Correct |
32 ms |
13436 KB |
Output is correct |
11 |
Correct |
34 ms |
13556 KB |
Output is correct |
12 |
Correct |
36 ms |
13244 KB |
Output is correct |
13 |
Correct |
35 ms |
13600 KB |
Output is correct |
14 |
Correct |
33 ms |
13664 KB |
Output is correct |
15 |
Correct |
38 ms |
13504 KB |
Output is correct |
16 |
Correct |
31 ms |
11308 KB |
Output is correct |
17 |
Correct |
32 ms |
11328 KB |
Output is correct |
18 |
Correct |
25 ms |
11260 KB |
Output is correct |
19 |
Correct |
28 ms |
11388 KB |
Output is correct |
20 |
Correct |
36 ms |
11848 KB |
Output is correct |
21 |
Correct |
27 ms |
11832 KB |
Output is correct |
22 |
Correct |
32 ms |
13928 KB |
Output is correct |
23 |
Correct |
26 ms |
11492 KB |
Output is correct |
24 |
Correct |
24 ms |
11508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1036 KB |
Output is correct |
2 |
Correct |
0 ms |
792 KB |
Output is correct |
3 |
Correct |
1 ms |
1052 KB |
Output is correct |
4 |
Correct |
2 ms |
1044 KB |
Output is correct |
5 |
Correct |
2 ms |
1184 KB |
Output is correct |
6 |
Correct |
2 ms |
1052 KB |
Output is correct |
7 |
Correct |
2 ms |
1036 KB |
Output is correct |
8 |
Correct |
2 ms |
1044 KB |
Output is correct |
9 |
Correct |
2 ms |
1032 KB |
Output is correct |
10 |
Correct |
2 ms |
1044 KB |
Output is correct |
11 |
Correct |
2 ms |
1052 KB |
Output is correct |
12 |
Correct |
2 ms |
1052 KB |
Output is correct |
13 |
Correct |
1 ms |
1044 KB |
Output is correct |
14 |
Correct |
1 ms |
1044 KB |
Output is correct |
15 |
Correct |
2 ms |
1040 KB |
Output is correct |
16 |
Correct |
1 ms |
1052 KB |
Output is correct |
17 |
Correct |
2 ms |
1036 KB |
Output is correct |
18 |
Correct |
2 ms |
1052 KB |
Output is correct |
19 |
Correct |
1 ms |
1044 KB |
Output is correct |
20 |
Correct |
2 ms |
1048 KB |
Output is correct |
21 |
Correct |
2 ms |
1052 KB |
Output is correct |
22 |
Correct |
2 ms |
1052 KB |
Output is correct |
23 |
Correct |
1 ms |
1200 KB |
Output is correct |
24 |
Correct |
2 ms |
1044 KB |
Output is correct |
25 |
Correct |
1 ms |
1036 KB |
Output is correct |
26 |
Correct |
2 ms |
1040 KB |
Output is correct |
27 |
Correct |
2 ms |
1052 KB |
Output is correct |
28 |
Correct |
2 ms |
1044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
11176 KB |
Output is correct |
2 |
Correct |
32 ms |
11616 KB |
Output is correct |
3 |
Correct |
0 ms |
780 KB |
Output is correct |
4 |
Correct |
20 ms |
11136 KB |
Output is correct |
5 |
Correct |
38 ms |
12304 KB |
Output is correct |
6 |
Correct |
34 ms |
12372 KB |
Output is correct |
7 |
Correct |
27 ms |
11372 KB |
Output is correct |
8 |
Correct |
33 ms |
11372 KB |
Output is correct |
9 |
Correct |
34 ms |
12328 KB |
Output is correct |
10 |
Correct |
36 ms |
12292 KB |
Output is correct |
11 |
Correct |
34 ms |
12400 KB |
Output is correct |
12 |
Correct |
40 ms |
12320 KB |
Output is correct |
13 |
Correct |
32 ms |
12292 KB |
Output is correct |
14 |
Correct |
40 ms |
12448 KB |
Output is correct |
15 |
Correct |
33 ms |
12368 KB |
Output is correct |
16 |
Correct |
32 ms |
12368 KB |
Output is correct |
17 |
Correct |
28 ms |
11972 KB |
Output is correct |
18 |
Correct |
32 ms |
12096 KB |
Output is correct |
19 |
Correct |
33 ms |
12324 KB |
Output is correct |
20 |
Correct |
32 ms |
12428 KB |
Output is correct |
21 |
Correct |
27 ms |
12356 KB |
Output is correct |
22 |
Correct |
28 ms |
12392 KB |
Output is correct |
23 |
Correct |
27 ms |
11696 KB |
Output is correct |
24 |
Correct |
24 ms |
11612 KB |
Output is correct |
25 |
Correct |
26 ms |
11768 KB |
Output is correct |
26 |
Correct |
27 ms |
11860 KB |
Output is correct |
27 |
Correct |
33 ms |
12532 KB |
Output is correct |
28 |
Correct |
32 ms |
12308 KB |
Output is correct |
29 |
Correct |
32 ms |
12172 KB |
Output is correct |
30 |
Correct |
26 ms |
12380 KB |
Output is correct |
31 |
Correct |
26 ms |
11748 KB |
Output is correct |
32 |
Correct |
25 ms |
11612 KB |
Output is correct |
33 |
Correct |
25 ms |
11804 KB |
Output is correct |
34 |
Correct |
28 ms |
12116 KB |
Output is correct |
35 |
Correct |
32 ms |
12428 KB |
Output is correct |
36 |
Correct |
28 ms |
12176 KB |
Output is correct |
37 |
Correct |
30 ms |
12024 KB |
Output is correct |
38 |
Correct |
35 ms |
12284 KB |
Output is correct |
39 |
Correct |
27 ms |
12028 KB |
Output is correct |
40 |
Correct |
36 ms |
12248 KB |
Output is correct |
41 |
Correct |
40 ms |
12348 KB |
Output is correct |
42 |
Correct |
35 ms |
12316 KB |
Output is correct |
43 |
Correct |
30 ms |
12536 KB |
Output is correct |
44 |
Correct |
34 ms |
12476 KB |
Output is correct |
45 |
Correct |
39 ms |
12340 KB |
Output is correct |
46 |
Correct |
34 ms |
12628 KB |
Output is correct |
47 |
Correct |
37 ms |
12032 KB |
Output is correct |
48 |
Correct |
26 ms |
12116 KB |
Output is correct |
49 |
Correct |
36 ms |
11960 KB |
Output is correct |
50 |
Correct |
37 ms |
12140 KB |
Output is correct |
51 |
Correct |
40 ms |
11716 KB |
Output is correct |
52 |
Correct |
26 ms |
11808 KB |
Output is correct |
53 |
Correct |
34 ms |
11852 KB |
Output is correct |
54 |
Correct |
29 ms |
12136 KB |
Output is correct |
55 |
Correct |
28 ms |
11868 KB |
Output is correct |
56 |
Correct |
26 ms |
11852 KB |
Output is correct |
57 |
Correct |
33 ms |
12124 KB |
Output is correct |
58 |
Correct |
28 ms |
11832 KB |
Output is correct |
59 |
Correct |
27 ms |
12108 KB |
Output is correct |
60 |
Correct |
28 ms |
11860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
11772 KB |
Output is correct |
2 |
Correct |
31 ms |
12092 KB |
Output is correct |
3 |
Correct |
1 ms |
784 KB |
Output is correct |
4 |
Correct |
23 ms |
11580 KB |
Output is correct |
5 |
Correct |
31 ms |
12656 KB |
Output is correct |
6 |
Correct |
41 ms |
12744 KB |
Output is correct |
7 |
Correct |
27 ms |
11652 KB |
Output is correct |
8 |
Correct |
27 ms |
11640 KB |
Output is correct |
9 |
Correct |
31 ms |
12624 KB |
Output is correct |
10 |
Correct |
31 ms |
12684 KB |
Output is correct |
11 |
Correct |
37 ms |
12652 KB |
Output is correct |
12 |
Correct |
37 ms |
12468 KB |
Output is correct |
13 |
Correct |
35 ms |
12680 KB |
Output is correct |
14 |
Correct |
31 ms |
12676 KB |
Output is correct |
15 |
Correct |
30 ms |
12752 KB |
Output is correct |
16 |
Correct |
33 ms |
12576 KB |
Output is correct |
17 |
Correct |
31 ms |
12488 KB |
Output is correct |
18 |
Correct |
36 ms |
12208 KB |
Output is correct |
19 |
Correct |
31 ms |
12148 KB |
Output is correct |
20 |
Correct |
28 ms |
12428 KB |
Output is correct |
21 |
Correct |
28 ms |
12424 KB |
Output is correct |
22 |
Correct |
31 ms |
12408 KB |
Output is correct |
23 |
Correct |
24 ms |
11592 KB |
Output is correct |
24 |
Correct |
27 ms |
11604 KB |
Output is correct |
25 |
Correct |
25 ms |
11852 KB |
Output is correct |
26 |
Correct |
26 ms |
11688 KB |
Output is correct |
27 |
Correct |
32 ms |
12332 KB |
Output is correct |
28 |
Correct |
28 ms |
12328 KB |
Output is correct |
29 |
Correct |
28 ms |
12252 KB |
Output is correct |
30 |
Correct |
27 ms |
12380 KB |
Output is correct |
31 |
Correct |
24 ms |
11616 KB |
Output is correct |
32 |
Correct |
26 ms |
11616 KB |
Output is correct |
33 |
Correct |
26 ms |
11904 KB |
Output is correct |
34 |
Correct |
25 ms |
11856 KB |
Output is correct |
35 |
Correct |
31 ms |
12132 KB |
Output is correct |
36 |
Correct |
26 ms |
12128 KB |
Output is correct |
37 |
Correct |
27 ms |
12124 KB |
Output is correct |
38 |
Correct |
27 ms |
12120 KB |
Output is correct |
39 |
Correct |
27 ms |
12096 KB |
Output is correct |
40 |
Correct |
26 ms |
12080 KB |
Output is correct |
41 |
Correct |
38 ms |
12460 KB |
Output is correct |
42 |
Correct |
28 ms |
12508 KB |
Output is correct |
43 |
Correct |
30 ms |
12372 KB |
Output is correct |
44 |
Correct |
32 ms |
12372 KB |
Output is correct |
45 |
Correct |
34 ms |
12760 KB |
Output is correct |
46 |
Correct |
34 ms |
12604 KB |
Output is correct |
47 |
Correct |
27 ms |
12088 KB |
Output is correct |
48 |
Correct |
28 ms |
12108 KB |
Output is correct |
49 |
Correct |
28 ms |
12072 KB |
Output is correct |
50 |
Correct |
28 ms |
12084 KB |
Output is correct |
51 |
Correct |
26 ms |
11856 KB |
Output is correct |
52 |
Correct |
25 ms |
11804 KB |
Output is correct |
53 |
Correct |
26 ms |
11768 KB |
Output is correct |
54 |
Correct |
25 ms |
11784 KB |
Output is correct |
55 |
Correct |
26 ms |
11776 KB |
Output is correct |
56 |
Correct |
26 ms |
11848 KB |
Output is correct |
57 |
Correct |
33 ms |
11960 KB |
Output is correct |
58 |
Correct |
25 ms |
12120 KB |
Output is correct |
59 |
Correct |
26 ms |
11868 KB |
Output is correct |
60 |
Correct |
25 ms |
11808 KB |
Output is correct |