#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
vector<vector<int>> adj;
vector<int> dist;
void bfs() {
queue<int> q;
dist.resize(adj.size(), INT_MAX);
q.push(0);
dist[0] = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
for (auto u : adj[v]) {
if (dist[u] > dist[v] + 1) {
dist[u] = dist[v] + 1;
q.push(u);
}
}
}
}
vector<int> s{0, 0, 1, 0, 1, 1};
vector<pair<int, int>> v;
void dfs(int ver, int par, int col, int len) {
v[ver] = {par, col};
int numchild = adj[ver].size() - (par != -1);
if (numchild > 1) {
for (auto c : adj[ver]) if (c != par) {
dfs(c, ver, !col, -1);
}
} else {
if (len == -1) {
if (col == 0) len = 1;
else len = 3;
}
for (auto c : adj[ver]) if (c != par) {
dfs(c, ver, s[len], (len + 1) % 6);
}
}
}
} // namespace
std::vector<int> Mark(int N, int M, int A, int B,
std::vector<int> U, std::vector<int> V) {
adj.resize(N);
for (int i = 0; i < M; ++i) {
adj[U[i]].push_back(V[i]);
adj[V[i]].push_back(U[i]);
}
if (A >= 3) {
bfs();
vector<int> ret(M);
for (int i = 0; i < M; ++i) {
ret[i] = min(dist[U[i]], dist[V[i]]) % 3;
}
return ret;
}
v.resize(N);
dfs(0, -1, 0, -1);
vector<int> ret(M);
for (int i = 0; i < M; ++i) {
if (v[U[i]].first == V[i]) {
ret[i] = v[U[i]].second;
} else {
ret[i] = v[V[i]].second;
}
}
return ret;
}
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
int A, B;
int prv;
vector<int> pat{0, 0, 1, 0, 1, 1};
vector<int> cur;
bool correct;
} // namespace
void Init(int A, int B) {
::A = A;
::B = B;
::prv = -1;
::correct = false;
}
int Move(std::vector<int> y) {
if (A >= 3) {
if (y[0] == 0) {
if (y[1] == 0) return 2;
return 1;
} else if (y[1] == 0) {
if (y[2] == 0) return 0;
return 2;
} else if (y[2] == 0) {
if (y[0] == 0) return 1;
return 0;
}
assert(false);
}
int cntadj = accumulate(begin(y), end(y), 0) + (prv != -1);
if (cntadj > 2) {
correct = true;
if (prv != -1 && y[prv] == 0) return -1;
if (prv != -1) y[prv]++;
if (y[0] == 1) return prv = 0;
else if (y[1] == 1) return prv = 1;
assert(false);
}
if (cntadj == 1) {
correct = true;
if (prv != -1) {
return -1;
} else {
if (y[0] == 1) return prv = 0;
else if (y[1] == 1) return prv = 1;
assert(false);
}
}
if (correct) {
if (y[0] > 0) return prv = 0;
else if (y[1] > 0) return prv = 1;
assert(false);
}
if (prv == -1) {
if (y[0] > 0) {
cur.push_back(0);
if (y[1] > 0) {
cur.push_back(1);
return prv = 1;
} else {
cur.push_back(0);
return prv = 0;
}
} else {
assert(y[1] > 0);
cur.push_back(1);
cur.push_back(1);
return prv = 1;
}
} else {
if (y[0] > 0) {
cur.push_back(0);
} else {
assert(y[1] > 0);
cur.push_back(1);
}
if (cur.size() == 5) {
for (int i = 0; i < 10; ++i) {
bool g = true;
for (int j = 0; j < 5; ++j) {
if (cur[j] != pat[(j + i) % size(pat)]) g = false;
}
if (g) {
correct = true;
return -1;
}
}
correct = true;
assert(y[cur.back()] > 0);
return prv = cur.back();
} else {
assert(y[cur.back()] > 0);
return prv = cur.back();
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
15388 KB |
Output is correct |
2 |
Correct |
0 ms |
508 KB |
Output is correct |
3 |
Correct |
34 ms |
14700 KB |
Output is correct |
4 |
Correct |
49 ms |
16372 KB |
Output is correct |
5 |
Correct |
46 ms |
16460 KB |
Output is correct |
6 |
Correct |
35 ms |
15104 KB |
Output is correct |
7 |
Correct |
38 ms |
15288 KB |
Output is correct |
8 |
Correct |
46 ms |
15960 KB |
Output is correct |
9 |
Correct |
46 ms |
15808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
15388 KB |
Output is correct |
2 |
Correct |
0 ms |
508 KB |
Output is correct |
3 |
Correct |
34 ms |
14700 KB |
Output is correct |
4 |
Correct |
49 ms |
16372 KB |
Output is correct |
5 |
Correct |
46 ms |
16460 KB |
Output is correct |
6 |
Correct |
35 ms |
15104 KB |
Output is correct |
7 |
Correct |
38 ms |
15288 KB |
Output is correct |
8 |
Correct |
46 ms |
15960 KB |
Output is correct |
9 |
Correct |
46 ms |
15808 KB |
Output is correct |
10 |
Correct |
35 ms |
13108 KB |
Output is correct |
11 |
Correct |
35 ms |
13168 KB |
Output is correct |
12 |
Correct |
32 ms |
13180 KB |
Output is correct |
13 |
Correct |
37 ms |
13076 KB |
Output is correct |
14 |
Correct |
33 ms |
13404 KB |
Output is correct |
15 |
Correct |
50 ms |
13704 KB |
Output is correct |
16 |
Correct |
43 ms |
16000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
12944 KB |
Output is correct |
2 |
Correct |
1 ms |
516 KB |
Output is correct |
3 |
Correct |
28 ms |
12468 KB |
Output is correct |
4 |
Correct |
53 ms |
14192 KB |
Output is correct |
5 |
Correct |
56 ms |
14240 KB |
Output is correct |
6 |
Correct |
35 ms |
12860 KB |
Output is correct |
7 |
Correct |
40 ms |
13032 KB |
Output is correct |
8 |
Correct |
40 ms |
13796 KB |
Output is correct |
9 |
Correct |
41 ms |
13548 KB |
Output is correct |
10 |
Correct |
46 ms |
13272 KB |
Output is correct |
11 |
Correct |
39 ms |
13280 KB |
Output is correct |
12 |
Correct |
50 ms |
13324 KB |
Output is correct |
13 |
Correct |
38 ms |
13284 KB |
Output is correct |
14 |
Correct |
39 ms |
13736 KB |
Output is correct |
15 |
Correct |
46 ms |
13628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
12944 KB |
Output is correct |
2 |
Correct |
1 ms |
516 KB |
Output is correct |
3 |
Correct |
28 ms |
12468 KB |
Output is correct |
4 |
Correct |
53 ms |
14192 KB |
Output is correct |
5 |
Correct |
56 ms |
14240 KB |
Output is correct |
6 |
Correct |
35 ms |
12860 KB |
Output is correct |
7 |
Correct |
40 ms |
13032 KB |
Output is correct |
8 |
Correct |
40 ms |
13796 KB |
Output is correct |
9 |
Correct |
41 ms |
13548 KB |
Output is correct |
10 |
Correct |
46 ms |
13272 KB |
Output is correct |
11 |
Correct |
39 ms |
13280 KB |
Output is correct |
12 |
Correct |
50 ms |
13324 KB |
Output is correct |
13 |
Correct |
38 ms |
13284 KB |
Output is correct |
14 |
Correct |
39 ms |
13736 KB |
Output is correct |
15 |
Correct |
46 ms |
13628 KB |
Output is correct |
16 |
Correct |
28 ms |
11320 KB |
Output is correct |
17 |
Correct |
33 ms |
11308 KB |
Output is correct |
18 |
Correct |
34 ms |
11292 KB |
Output is correct |
19 |
Correct |
30 ms |
11192 KB |
Output is correct |
20 |
Correct |
38 ms |
11924 KB |
Output is correct |
21 |
Correct |
36 ms |
11688 KB |
Output is correct |
22 |
Correct |
41 ms |
13696 KB |
Output is correct |
23 |
Correct |
38 ms |
11432 KB |
Output is correct |
24 |
Correct |
32 ms |
11372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
900 KB |
Output is correct |
2 |
Correct |
0 ms |
508 KB |
Output is correct |
3 |
Correct |
2 ms |
896 KB |
Output is correct |
4 |
Correct |
2 ms |
904 KB |
Output is correct |
5 |
Correct |
2 ms |
896 KB |
Output is correct |
6 |
Correct |
2 ms |
896 KB |
Output is correct |
7 |
Correct |
2 ms |
896 KB |
Output is correct |
8 |
Correct |
2 ms |
896 KB |
Output is correct |
9 |
Correct |
2 ms |
896 KB |
Output is correct |
10 |
Correct |
2 ms |
904 KB |
Output is correct |
11 |
Correct |
2 ms |
896 KB |
Output is correct |
12 |
Correct |
2 ms |
896 KB |
Output is correct |
13 |
Correct |
2 ms |
908 KB |
Output is correct |
14 |
Correct |
2 ms |
908 KB |
Output is correct |
15 |
Correct |
2 ms |
904 KB |
Output is correct |
16 |
Correct |
2 ms |
900 KB |
Output is correct |
17 |
Correct |
2 ms |
900 KB |
Output is correct |
18 |
Correct |
2 ms |
908 KB |
Output is correct |
19 |
Correct |
2 ms |
908 KB |
Output is correct |
20 |
Correct |
2 ms |
900 KB |
Output is correct |
21 |
Correct |
2 ms |
900 KB |
Output is correct |
22 |
Correct |
2 ms |
908 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
2 ms |
900 KB |
Output is correct |
25 |
Correct |
2 ms |
900 KB |
Output is correct |
26 |
Correct |
2 ms |
900 KB |
Output is correct |
27 |
Correct |
2 ms |
908 KB |
Output is correct |
28 |
Correct |
2 ms |
900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
11072 KB |
Output is correct |
2 |
Correct |
38 ms |
12296 KB |
Output is correct |
3 |
Correct |
0 ms |
516 KB |
Output is correct |
4 |
Correct |
30 ms |
11084 KB |
Output is correct |
5 |
Correct |
46 ms |
13932 KB |
Output is correct |
6 |
Correct |
41 ms |
13980 KB |
Output is correct |
7 |
Correct |
33 ms |
13116 KB |
Output is correct |
8 |
Correct |
34 ms |
13104 KB |
Output is correct |
9 |
Correct |
48 ms |
14076 KB |
Output is correct |
10 |
Correct |
47 ms |
14040 KB |
Output is correct |
11 |
Correct |
49 ms |
14012 KB |
Output is correct |
12 |
Correct |
40 ms |
14012 KB |
Output is correct |
13 |
Correct |
43 ms |
13944 KB |
Output is correct |
14 |
Correct |
46 ms |
14012 KB |
Output is correct |
15 |
Correct |
43 ms |
13956 KB |
Output is correct |
16 |
Correct |
37 ms |
14000 KB |
Output is correct |
17 |
Correct |
41 ms |
13708 KB |
Output is correct |
18 |
Correct |
43 ms |
13736 KB |
Output is correct |
19 |
Correct |
42 ms |
13624 KB |
Output is correct |
20 |
Correct |
41 ms |
13700 KB |
Output is correct |
21 |
Correct |
42 ms |
13656 KB |
Output is correct |
22 |
Correct |
44 ms |
13744 KB |
Output is correct |
23 |
Correct |
32 ms |
11516 KB |
Output is correct |
24 |
Correct |
35 ms |
11516 KB |
Output is correct |
25 |
Correct |
33 ms |
12028 KB |
Output is correct |
26 |
Correct |
37 ms |
12044 KB |
Output is correct |
27 |
Correct |
39 ms |
12836 KB |
Output is correct |
28 |
Correct |
43 ms |
12740 KB |
Output is correct |
29 |
Correct |
40 ms |
12888 KB |
Output is correct |
30 |
Correct |
43 ms |
12848 KB |
Output is correct |
31 |
Correct |
34 ms |
11572 KB |
Output is correct |
32 |
Correct |
33 ms |
11508 KB |
Output is correct |
33 |
Correct |
30 ms |
11960 KB |
Output is correct |
34 |
Correct |
34 ms |
11960 KB |
Output is correct |
35 |
Correct |
41 ms |
12576 KB |
Output is correct |
36 |
Correct |
42 ms |
12552 KB |
Output is correct |
37 |
Correct |
43 ms |
12524 KB |
Output is correct |
38 |
Correct |
36 ms |
12600 KB |
Output is correct |
39 |
Correct |
39 ms |
12612 KB |
Output is correct |
40 |
Correct |
37 ms |
12544 KB |
Output is correct |
41 |
Correct |
46 ms |
13236 KB |
Output is correct |
42 |
Correct |
42 ms |
13336 KB |
Output is correct |
43 |
Correct |
38 ms |
13268 KB |
Output is correct |
44 |
Correct |
37 ms |
13360 KB |
Output is correct |
45 |
Correct |
52 ms |
13224 KB |
Output is correct |
46 |
Correct |
48 ms |
13288 KB |
Output is correct |
47 |
Correct |
41 ms |
12436 KB |
Output is correct |
48 |
Correct |
34 ms |
12416 KB |
Output is correct |
49 |
Correct |
33 ms |
12396 KB |
Output is correct |
50 |
Correct |
39 ms |
12560 KB |
Output is correct |
51 |
Correct |
34 ms |
11740 KB |
Output is correct |
52 |
Correct |
34 ms |
11844 KB |
Output is correct |
53 |
Correct |
32 ms |
11952 KB |
Output is correct |
54 |
Correct |
32 ms |
11792 KB |
Output is correct |
55 |
Correct |
32 ms |
11888 KB |
Output is correct |
56 |
Correct |
31 ms |
11832 KB |
Output is correct |
57 |
Correct |
37 ms |
11784 KB |
Output is correct |
58 |
Correct |
33 ms |
11836 KB |
Output is correct |
59 |
Correct |
33 ms |
11800 KB |
Output is correct |
60 |
Correct |
31 ms |
11888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
11104 KB |
Output is correct |
2 |
Correct |
33 ms |
12072 KB |
Output is correct |
3 |
Correct |
0 ms |
508 KB |
Output is correct |
4 |
Correct |
28 ms |
11036 KB |
Output is correct |
5 |
Correct |
48 ms |
14012 KB |
Output is correct |
6 |
Correct |
42 ms |
14048 KB |
Output is correct |
7 |
Correct |
35 ms |
13224 KB |
Output is correct |
8 |
Correct |
33 ms |
13184 KB |
Output is correct |
9 |
Correct |
46 ms |
13928 KB |
Output is correct |
10 |
Correct |
40 ms |
14008 KB |
Output is correct |
11 |
Correct |
40 ms |
14108 KB |
Output is correct |
12 |
Correct |
40 ms |
13988 KB |
Output is correct |
13 |
Correct |
38 ms |
14132 KB |
Output is correct |
14 |
Correct |
39 ms |
14040 KB |
Output is correct |
15 |
Correct |
38 ms |
14040 KB |
Output is correct |
16 |
Correct |
41 ms |
14136 KB |
Output is correct |
17 |
Correct |
37 ms |
13732 KB |
Output is correct |
18 |
Correct |
42 ms |
13644 KB |
Output is correct |
19 |
Correct |
37 ms |
13696 KB |
Output is correct |
20 |
Correct |
38 ms |
13816 KB |
Output is correct |
21 |
Correct |
37 ms |
13680 KB |
Output is correct |
22 |
Correct |
37 ms |
13748 KB |
Output is correct |
23 |
Correct |
34 ms |
11512 KB |
Output is correct |
24 |
Correct |
32 ms |
11476 KB |
Output is correct |
25 |
Correct |
32 ms |
11984 KB |
Output is correct |
26 |
Correct |
33 ms |
12104 KB |
Output is correct |
27 |
Correct |
45 ms |
12712 KB |
Output is correct |
28 |
Correct |
38 ms |
12724 KB |
Output is correct |
29 |
Correct |
36 ms |
12812 KB |
Output is correct |
30 |
Correct |
36 ms |
12812 KB |
Output is correct |
31 |
Correct |
33 ms |
11520 KB |
Output is correct |
32 |
Correct |
30 ms |
11556 KB |
Output is correct |
33 |
Correct |
32 ms |
12144 KB |
Output is correct |
34 |
Correct |
32 ms |
12072 KB |
Output is correct |
35 |
Correct |
35 ms |
12536 KB |
Output is correct |
36 |
Correct |
38 ms |
12624 KB |
Output is correct |
37 |
Correct |
37 ms |
12532 KB |
Output is correct |
38 |
Correct |
36 ms |
12600 KB |
Output is correct |
39 |
Correct |
35 ms |
12628 KB |
Output is correct |
40 |
Correct |
43 ms |
12536 KB |
Output is correct |
41 |
Correct |
39 ms |
13244 KB |
Output is correct |
42 |
Correct |
37 ms |
13204 KB |
Output is correct |
43 |
Correct |
40 ms |
13272 KB |
Output is correct |
44 |
Correct |
38 ms |
13376 KB |
Output is correct |
45 |
Correct |
37 ms |
13324 KB |
Output is correct |
46 |
Correct |
41 ms |
13272 KB |
Output is correct |
47 |
Correct |
35 ms |
12476 KB |
Output is correct |
48 |
Correct |
35 ms |
12532 KB |
Output is correct |
49 |
Correct |
40 ms |
12388 KB |
Output is correct |
50 |
Correct |
37 ms |
12524 KB |
Output is correct |
51 |
Correct |
32 ms |
11776 KB |
Output is correct |
52 |
Correct |
32 ms |
11808 KB |
Output is correct |
53 |
Correct |
31 ms |
11908 KB |
Output is correct |
54 |
Correct |
39 ms |
11832 KB |
Output is correct |
55 |
Correct |
32 ms |
11868 KB |
Output is correct |
56 |
Correct |
31 ms |
11740 KB |
Output is correct |
57 |
Correct |
31 ms |
11800 KB |
Output is correct |
58 |
Correct |
33 ms |
11688 KB |
Output is correct |
59 |
Correct |
32 ms |
11936 KB |
Output is correct |
60 |
Correct |
34 ms |
11888 KB |
Output is correct |