#include <bits/stdc++.h>
#include "Anthony.h"
using namespace std;
namespace {
const int N_MAX = 20000;
const int pattern[] = {0, 1, 0, 0, 1, 1};
int N, M, A, B;
int edge_u[N_MAX], edge_v[N_MAX];
vector <int> adj[N_MAX];
int other (int i, int u) {
return (u != edge_v[i] ? edge_v[i] : edge_u[i]);
}
int up_edge[N_MAX];
int color[N_MAX + 1];
int chain[N_MAX];
void dfs () {
fill(up_edge, up_edge + N, -1);
up_edge[0] = M; color[M] = 1 - N % 2;
chain[0] = -1;
queue <int> q;
q.push(0);
while (q.empty() == false) {
int u = q.front();
q.pop();
if ((int) adj[u].size() == 2 && u != 0) {
if (chain[u] == -1) {
chain[u] = (1 - color[up_edge[u]]);
} else {
chain[u]++;
}
} else {
chain[u] = -1;
}
for (int i : adj[u]) {
int v = other(i, u);
if (up_edge[v] == -1) {
up_edge[v] = i;
color[i] = (chain[u] == -1 ? 1 - color[up_edge[u]] : pattern[chain[u] % 6]);
chain[v] = chain[u];
q.push(v);
}
}
}
}
int dist[N_MAX];
void bfs () {
fill(dist, dist + N, -1);
up_edge[0] = M; color[M] = 2;
dist[0] = 0;
queue <int> q;
q.push(0);
while (q.empty() == false) {
int u = q.front();
q.pop();
for (int i : adj[u]) {
int v = other(i, u);
if (dist[v] == -1) {
up_edge[v] = i;
dist[v] = dist[u] + 1;
color[i] = (color[up_edge[u]] + 1) % 3;
q.push(v);
} else if (dist[u] <= dist[v]){
color[i] = (color[up_edge[u]] + 1) % 3;
}
}
}
}
}
vector <int> Mark (int _N, int _M, int _A, int _B, vector <int> _U, vector <int> _V) {
N = _N; M = _M; A = _A; B = _B;
for (int i = 0; i < M; i++) {
edge_u[i] = _U[i]; edge_v[i] = _V[i];
adj[edge_u[i]].push_back(i);
adj[edge_v[i]].push_back(i);
}
if (B > 0) {
dfs();
} else {
bfs();
}
vector <int> X(M);
copy(color, color + M, X.begin());
for (int u = 0; u < N; u++) {
adj[u].clear();
up_edge[u] = 0;
}
return X;
}
#include <bits/stdc++.h>
#include "Catherine.h"
using namespace std;
namespace {
const int pattern[] = {0, 1, 0, 0, 1, 1};
int A, B;
vector <int> cols;
bool passed_test;
}
void Init (int _A, int _B) {
A = _A; B = _B;
cols.clear();
passed_test = false;
}
int Move (vector <int> cnt_col) {
if (B > 0) {
int deg = cnt_col[0] + cnt_col[1] + 1;
// First move
if (cols.empty() == true) {
deg--;
// If leaf, take the only option
if (deg == 1) {
passed_test = true;
cols.push_back((cnt_col[0] > 0 ? 0 : 1));
return cols.back();
}
// If not crossroad, take any option
if (deg == 2) {
if (cnt_col[0] == cnt_col[1]) {
cols.push_back(1);
cols.push_back(0);
} else if (cnt_col[0] > 0) {
cols.push_back(0);
cols.push_back(0);
} else {
cols.push_back(1);
cols.push_back(1);
}
return cols.back();
}
// If crossroad, take the only option with frequency 1
passed_test = true;
cols.push_back((cnt_col[0] == 1 ? 0 : 1));
return cols.back();
}
// If leaf, turn back
if (deg == 1) {
passed_test = true;
cols = {cols.back()};
return -1;
}
// If not crossroad, check for pattern
if (deg == 2) {
cols.push_back((cnt_col[0] > 0 ? 0 : 1));
if (passed_test == false && (int) cols.size() == 5) {
int down = false;
for (int i = 0; i < 6; i++) {
down = true;
for (int j = 0; j < 5; j++) {
if (cols[j] != pattern[(i + j) % 6]) {
down = false;
break;
}
}
if (down == true) {
break;
}
}
passed_test = true;
if (down == true) {
cols.pop_back();
cols = {cols.back()};
return -1;
}
}
return cols.back();
}
// If crossroad, check for count
passed_test = true;
if (cnt_col[0] == 0 || cnt_col[1] == 0) {
cols = {cols.back()};
return -1;
} else {
cols.push_back(1 - cols.back());
return cols.back();
}
} else {
if ((cnt_col[0] > 0) + (cnt_col[1] > 0) + (cnt_col[2] > 0) == 1) {
return (cnt_col[0] > 0 ? 0 : (cnt_col[1] > 0 ? 1 : 2));
} else {
return (cnt_col[0] == 0 ? 1 : (cnt_col[1] == 0 ? 2 : 0));
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
16236 KB |
Output is correct |
2 |
Correct |
1 ms |
1300 KB |
Output is correct |
3 |
Correct |
26 ms |
15680 KB |
Output is correct |
4 |
Correct |
35 ms |
17312 KB |
Output is correct |
5 |
Correct |
34 ms |
17232 KB |
Output is correct |
6 |
Correct |
26 ms |
16196 KB |
Output is correct |
7 |
Correct |
28 ms |
15988 KB |
Output is correct |
8 |
Correct |
32 ms |
16888 KB |
Output is correct |
9 |
Correct |
35 ms |
16620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
16236 KB |
Output is correct |
2 |
Correct |
1 ms |
1300 KB |
Output is correct |
3 |
Correct |
26 ms |
15680 KB |
Output is correct |
4 |
Correct |
35 ms |
17312 KB |
Output is correct |
5 |
Correct |
34 ms |
17232 KB |
Output is correct |
6 |
Correct |
26 ms |
16196 KB |
Output is correct |
7 |
Correct |
28 ms |
15988 KB |
Output is correct |
8 |
Correct |
32 ms |
16888 KB |
Output is correct |
9 |
Correct |
35 ms |
16620 KB |
Output is correct |
10 |
Correct |
31 ms |
14140 KB |
Output is correct |
11 |
Correct |
25 ms |
14152 KB |
Output is correct |
12 |
Correct |
35 ms |
13928 KB |
Output is correct |
13 |
Correct |
25 ms |
14148 KB |
Output is correct |
14 |
Correct |
27 ms |
14404 KB |
Output is correct |
15 |
Correct |
34 ms |
14664 KB |
Output is correct |
16 |
Correct |
30 ms |
16684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
13908 KB |
Output is correct |
2 |
Correct |
1 ms |
1312 KB |
Output is correct |
3 |
Correct |
25 ms |
13520 KB |
Output is correct |
4 |
Correct |
32 ms |
15184 KB |
Output is correct |
5 |
Correct |
32 ms |
15184 KB |
Output is correct |
6 |
Correct |
26 ms |
13864 KB |
Output is correct |
7 |
Correct |
31 ms |
13808 KB |
Output is correct |
8 |
Correct |
31 ms |
14492 KB |
Output is correct |
9 |
Correct |
34 ms |
14432 KB |
Output is correct |
10 |
Correct |
34 ms |
14216 KB |
Output is correct |
11 |
Correct |
28 ms |
14164 KB |
Output is correct |
12 |
Correct |
28 ms |
14156 KB |
Output is correct |
13 |
Correct |
34 ms |
14092 KB |
Output is correct |
14 |
Correct |
30 ms |
14520 KB |
Output is correct |
15 |
Correct |
30 ms |
14356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
13908 KB |
Output is correct |
2 |
Correct |
1 ms |
1312 KB |
Output is correct |
3 |
Correct |
25 ms |
13520 KB |
Output is correct |
4 |
Correct |
32 ms |
15184 KB |
Output is correct |
5 |
Correct |
32 ms |
15184 KB |
Output is correct |
6 |
Correct |
26 ms |
13864 KB |
Output is correct |
7 |
Correct |
31 ms |
13808 KB |
Output is correct |
8 |
Correct |
31 ms |
14492 KB |
Output is correct |
9 |
Correct |
34 ms |
14432 KB |
Output is correct |
10 |
Correct |
34 ms |
14216 KB |
Output is correct |
11 |
Correct |
28 ms |
14164 KB |
Output is correct |
12 |
Correct |
28 ms |
14156 KB |
Output is correct |
13 |
Correct |
34 ms |
14092 KB |
Output is correct |
14 |
Correct |
30 ms |
14520 KB |
Output is correct |
15 |
Correct |
30 ms |
14356 KB |
Output is correct |
16 |
Correct |
23 ms |
12100 KB |
Output is correct |
17 |
Correct |
24 ms |
12172 KB |
Output is correct |
18 |
Correct |
26 ms |
12120 KB |
Output is correct |
19 |
Correct |
25 ms |
12096 KB |
Output is correct |
20 |
Correct |
26 ms |
12812 KB |
Output is correct |
21 |
Correct |
26 ms |
12584 KB |
Output is correct |
22 |
Correct |
30 ms |
14488 KB |
Output is correct |
23 |
Correct |
25 ms |
12356 KB |
Output is correct |
24 |
Correct |
26 ms |
12420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1564 KB |
Output is correct |
2 |
Correct |
1 ms |
1300 KB |
Output is correct |
3 |
Correct |
1 ms |
1564 KB |
Output is correct |
4 |
Correct |
2 ms |
1564 KB |
Output is correct |
5 |
Correct |
2 ms |
1568 KB |
Output is correct |
6 |
Correct |
2 ms |
1564 KB |
Output is correct |
7 |
Correct |
2 ms |
1568 KB |
Output is correct |
8 |
Correct |
2 ms |
1572 KB |
Output is correct |
9 |
Correct |
2 ms |
1572 KB |
Output is correct |
10 |
Correct |
2 ms |
1572 KB |
Output is correct |
11 |
Correct |
2 ms |
1568 KB |
Output is correct |
12 |
Correct |
2 ms |
1564 KB |
Output is correct |
13 |
Correct |
1 ms |
1564 KB |
Output is correct |
14 |
Correct |
2 ms |
1564 KB |
Output is correct |
15 |
Correct |
2 ms |
1528 KB |
Output is correct |
16 |
Correct |
2 ms |
1564 KB |
Output is correct |
17 |
Correct |
2 ms |
1564 KB |
Output is correct |
18 |
Correct |
1 ms |
1572 KB |
Output is correct |
19 |
Correct |
2 ms |
1552 KB |
Output is correct |
20 |
Correct |
2 ms |
1564 KB |
Output is correct |
21 |
Correct |
2 ms |
1564 KB |
Output is correct |
22 |
Correct |
2 ms |
1564 KB |
Output is correct |
23 |
Correct |
2 ms |
1572 KB |
Output is correct |
24 |
Correct |
2 ms |
1556 KB |
Output is correct |
25 |
Correct |
2 ms |
1564 KB |
Output is correct |
26 |
Correct |
2 ms |
1556 KB |
Output is correct |
27 |
Correct |
2 ms |
1572 KB |
Output is correct |
28 |
Correct |
2 ms |
1564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
12096 KB |
Output is correct |
2 |
Correct |
26 ms |
12620 KB |
Output is correct |
3 |
Correct |
1 ms |
1300 KB |
Output is correct |
4 |
Correct |
20 ms |
11812 KB |
Output is correct |
5 |
Correct |
32 ms |
13048 KB |
Output is correct |
6 |
Correct |
30 ms |
13048 KB |
Output is correct |
7 |
Correct |
26 ms |
12120 KB |
Output is correct |
8 |
Correct |
25 ms |
12120 KB |
Output is correct |
9 |
Correct |
30 ms |
13136 KB |
Output is correct |
10 |
Correct |
28 ms |
13348 KB |
Output is correct |
11 |
Correct |
28 ms |
13096 KB |
Output is correct |
12 |
Correct |
40 ms |
12992 KB |
Output is correct |
13 |
Correct |
33 ms |
13128 KB |
Output is correct |
14 |
Correct |
28 ms |
13128 KB |
Output is correct |
15 |
Correct |
28 ms |
13140 KB |
Output is correct |
16 |
Correct |
34 ms |
13304 KB |
Output is correct |
17 |
Correct |
28 ms |
12868 KB |
Output is correct |
18 |
Correct |
27 ms |
12844 KB |
Output is correct |
19 |
Correct |
28 ms |
12776 KB |
Output is correct |
20 |
Correct |
28 ms |
12884 KB |
Output is correct |
21 |
Correct |
33 ms |
12860 KB |
Output is correct |
22 |
Correct |
27 ms |
12960 KB |
Output is correct |
23 |
Correct |
26 ms |
12116 KB |
Output is correct |
24 |
Correct |
24 ms |
12184 KB |
Output is correct |
25 |
Correct |
24 ms |
12372 KB |
Output is correct |
26 |
Correct |
25 ms |
12360 KB |
Output is correct |
27 |
Correct |
26 ms |
12624 KB |
Output is correct |
28 |
Correct |
27 ms |
13052 KB |
Output is correct |
29 |
Correct |
26 ms |
12848 KB |
Output is correct |
30 |
Correct |
26 ms |
12832 KB |
Output is correct |
31 |
Correct |
25 ms |
12112 KB |
Output is correct |
32 |
Correct |
25 ms |
11956 KB |
Output is correct |
33 |
Correct |
26 ms |
12356 KB |
Output is correct |
34 |
Correct |
24 ms |
12368 KB |
Output is correct |
35 |
Correct |
27 ms |
12700 KB |
Output is correct |
36 |
Correct |
26 ms |
12800 KB |
Output is correct |
37 |
Correct |
26 ms |
12616 KB |
Output is correct |
38 |
Correct |
34 ms |
12572 KB |
Output is correct |
39 |
Correct |
26 ms |
12624 KB |
Output is correct |
40 |
Correct |
26 ms |
12812 KB |
Output is correct |
41 |
Correct |
26 ms |
12812 KB |
Output is correct |
42 |
Correct |
27 ms |
12664 KB |
Output is correct |
43 |
Correct |
30 ms |
12696 KB |
Output is correct |
44 |
Correct |
27 ms |
12872 KB |
Output is correct |
45 |
Correct |
27 ms |
12792 KB |
Output is correct |
46 |
Correct |
27 ms |
12972 KB |
Output is correct |
47 |
Correct |
26 ms |
12640 KB |
Output is correct |
48 |
Correct |
26 ms |
12616 KB |
Output is correct |
49 |
Correct |
26 ms |
12616 KB |
Output is correct |
50 |
Correct |
30 ms |
12872 KB |
Output is correct |
51 |
Correct |
26 ms |
12356 KB |
Output is correct |
52 |
Correct |
27 ms |
12568 KB |
Output is correct |
53 |
Correct |
24 ms |
12376 KB |
Output is correct |
54 |
Correct |
27 ms |
12368 KB |
Output is correct |
55 |
Correct |
24 ms |
12488 KB |
Output is correct |
56 |
Correct |
25 ms |
12620 KB |
Output is correct |
57 |
Correct |
25 ms |
12300 KB |
Output is correct |
58 |
Correct |
28 ms |
12424 KB |
Output is correct |
59 |
Correct |
24 ms |
12120 KB |
Output is correct |
60 |
Correct |
25 ms |
12348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
12112 KB |
Output is correct |
2 |
Correct |
26 ms |
12620 KB |
Output is correct |
3 |
Correct |
1 ms |
1300 KB |
Output is correct |
4 |
Correct |
22 ms |
11824 KB |
Output is correct |
5 |
Correct |
30 ms |
13136 KB |
Output is correct |
6 |
Correct |
31 ms |
13132 KB |
Output is correct |
7 |
Correct |
25 ms |
12092 KB |
Output is correct |
8 |
Correct |
25 ms |
12100 KB |
Output is correct |
9 |
Correct |
28 ms |
13056 KB |
Output is correct |
10 |
Correct |
28 ms |
13124 KB |
Output is correct |
11 |
Correct |
28 ms |
13204 KB |
Output is correct |
12 |
Correct |
34 ms |
13172 KB |
Output is correct |
13 |
Correct |
28 ms |
13192 KB |
Output is correct |
14 |
Correct |
32 ms |
13392 KB |
Output is correct |
15 |
Correct |
30 ms |
13064 KB |
Output is correct |
16 |
Correct |
34 ms |
13224 KB |
Output is correct |
17 |
Correct |
31 ms |
12864 KB |
Output is correct |
18 |
Correct |
30 ms |
12836 KB |
Output is correct |
19 |
Correct |
27 ms |
12872 KB |
Output is correct |
20 |
Correct |
27 ms |
13112 KB |
Output is correct |
21 |
Correct |
27 ms |
12876 KB |
Output is correct |
22 |
Correct |
27 ms |
12804 KB |
Output is correct |
23 |
Correct |
24 ms |
12104 KB |
Output is correct |
24 |
Correct |
25 ms |
11924 KB |
Output is correct |
25 |
Correct |
25 ms |
12420 KB |
Output is correct |
26 |
Correct |
25 ms |
12364 KB |
Output is correct |
27 |
Correct |
26 ms |
12884 KB |
Output is correct |
28 |
Correct |
26 ms |
12860 KB |
Output is correct |
29 |
Correct |
26 ms |
12636 KB |
Output is correct |
30 |
Correct |
27 ms |
12820 KB |
Output is correct |
31 |
Correct |
25 ms |
12120 KB |
Output is correct |
32 |
Correct |
24 ms |
12124 KB |
Output is correct |
33 |
Correct |
25 ms |
12160 KB |
Output is correct |
34 |
Correct |
28 ms |
12356 KB |
Output is correct |
35 |
Correct |
26 ms |
12592 KB |
Output is correct |
36 |
Correct |
26 ms |
12660 KB |
Output is correct |
37 |
Correct |
27 ms |
12620 KB |
Output is correct |
38 |
Correct |
26 ms |
12804 KB |
Output is correct |
39 |
Correct |
26 ms |
12780 KB |
Output is correct |
40 |
Correct |
36 ms |
12696 KB |
Output is correct |
41 |
Correct |
27 ms |
12872 KB |
Output is correct |
42 |
Correct |
27 ms |
12628 KB |
Output is correct |
43 |
Correct |
27 ms |
12776 KB |
Output is correct |
44 |
Correct |
28 ms |
13168 KB |
Output is correct |
45 |
Correct |
27 ms |
12812 KB |
Output is correct |
46 |
Correct |
28 ms |
13000 KB |
Output is correct |
47 |
Correct |
27 ms |
12612 KB |
Output is correct |
48 |
Correct |
26 ms |
12728 KB |
Output is correct |
49 |
Correct |
25 ms |
12620 KB |
Output is correct |
50 |
Correct |
26 ms |
12548 KB |
Output is correct |
51 |
Correct |
24 ms |
12360 KB |
Output is correct |
52 |
Correct |
30 ms |
12456 KB |
Output is correct |
53 |
Correct |
26 ms |
12556 KB |
Output is correct |
54 |
Correct |
24 ms |
12352 KB |
Output is correct |
55 |
Correct |
27 ms |
12172 KB |
Output is correct |
56 |
Correct |
25 ms |
12440 KB |
Output is correct |
57 |
Correct |
25 ms |
12568 KB |
Output is correct |
58 |
Correct |
27 ms |
12372 KB |
Output is correct |
59 |
Correct |
24 ms |
12124 KB |
Output is correct |
60 |
Correct |
24 ms |
12092 KB |
Output is correct |