#include "Anthony.h"
#include <iostream>
#include <vector>
#include <queue>
#include <array>
#define ll long long
using namespace std;
namespace {
queue <array<ll, 2>> Q;
bool visited[20000], heavy[20000];
vector <int> E;
vector <array<ll, 2>> adj[20000];
void AmodeA() {
Q.push({0, 0});
while (!Q.empty()) {
auto [u, w] = Q.front();
Q.pop();
for (auto [v, x] : adj[u]) {
if (E[x] == -1) E[x] = w;
if (!visited[v]) {
visited[v] = 1;
Q.push({v, (w+1) % 3});
}
}
}
}
void dfs(ll u, ll p) {
ll chd_cnt = 0;
for (auto [v, x] : adj[u]) {
if (v != p) {
++chd_cnt;
dfs(v, u);
}
}
if (chd_cnt != 1 || p == -1) heavy[u] = 1;
}
void solve(ll u, ll p, ll w, ll z) {
for (auto [v, x] : adj[u]) {
if (v != p) {
if (heavy[u] && heavy[v]) {
E[x] = w^1;
solve(v, u, E[x], 0);
}
else if (heavy[u] && !heavy[v]) {
E[x] = w^1;
solve(v, u, E[x], 1);
}
else {
if (z == 2 || z == 4 || z == 5) E[x] = w;
else E[x] = w^1;
solve(v, u, E[x], (z+1) % 6);
}
}
}
}
void AmodeB() {
dfs(0, -1);
solve(0, -1, 1, 0);
}
}
std::vector<int> Mark(int N, int M, int A, int B,
std::vector<int> U, std::vector<int> V) {
E.resize(M);
for (int i=0; i<M; ++i) {
E[i] = -1;
adj[U[i]].push_back({V[i], i});
adj[V[i]].push_back({U[i], i});
}
if (!B) AmodeA();
else AmodeB();
return E;
}
#include "Catherine.h"
#include <iostream>
#include <vector>
#define ll long long
using namespace std;
namespace {
bool mode;
vector <ll> V;
ll p = -1, dir = -1, x = 0, rev = 0, l = 1e18, r = 1e18;
bool isinitSame;
int CmodeA(vector <int> y) {
ll cnt = 0, id;
for (int i=0; i<3; ++i) {
if (y[i] > 0) {
++cnt;
id = i;
}
}
if (cnt == 1) return id;
if (y[0] && y[1]) return 0;
else if (y[0] && y[2]) return 2;
else return 1;
}
int CmodeB(vector <int> y) {
if (dir == 1e18) {
if (!y[0]) return p = 1;
else if (!y[1]) return p = 0;
p ^= 1;
return p;
}
else if (dir == -1) {
if (!y[0] && y[1] == 1) {
dir = 1e18;
return p = 1;
}
else if (y[0] == 1 && !y[1]) {
dir = 1e18;
return p = 0;
}
if (y[0] == 1 && y[1] > 1) {
dir = 1e18;
return p = 0;
}
else if (y[0] > 1 && y[1] == 1) {
dir = 1e18;
return p = 1;
}
dir = 0;
if (!y[0] || !y[1]) {
isinitSame = 1;
if (y[0]) return p = 0;
else return p = 1;
}
else {
x = 1;
return p = 0;
}
}
if (!y[0] && !y[1]) {
dir = 1e18;
return -1;
}
else if (min(y[0], y[1]) == 0 && max(y[0], y[1]) > 1) {
dir = 1e18;
return -1;
}
else if (min(y[0], y[1]) >= 1) {
dir = 1e18;
p ^= 1;
return p;
}
if (!isinitSame) {
//cout << l << " " << r << " " << x << " " << rev << endl;
if (rev) {
--rev;
if (y[0]) return p = 0;
else return p = 1;
}
else if (l == 1e18) {
if (y[0]) {
if (x == 2) {
l = 3;
rev = 1, x = 0;
return -1;
}
else {
++x;
return p = 0;
}
}
else {
l = x;
if (x == 2) rev = 1;
x = 0;
return -1;
}
}
else if (r == 1e18) {
if (y[1]) {
++x;
if (x == 1) return p = 1;
else if (x == 2) {
if (l >= 2) {
r = 2;
return -1;
}
else {
++x;
return p = 1;
}
}
else {
r = 3;
rev = 1;
return -1;
}
}
else {
r = x;
if (x == 2) rev = 1;
return -1;
}
}
else {
if (l == r) ++r;
if ((l == 1 && r == 2) || (l == 2 && r == 3) || (l == 3 && r == 1)) {
dir = 1e18;
p = 0;
if (y[0]) return 0;
else return -1;
}
else {
dir = 1e18;
p = 1;
if (y[1]) return 1;
else return -1;
}
}
}
else {
if (rev) {
--rev;
if (y[0]) return p = 0;
else return p = 1;
}
else if (dir == 0) {
if ((y[0] && !p) || (y[1] && p)) {
dir = 1;
return p;
}
else {
dir = 2;
if (y[0]) return p = 0;
else return p = 1;
}
}
else if (dir == 1) {
if (y[0]) {
V.push_back(0);
if (V.size() == 1) return p = 0;
}
else {
V.push_back(1);
if (V.size() == 1) return p = 1;
}
if (V.size() == 2) {
if (V[0] == V[1]) {
dir = 1e18;
if (y[0]) return p = 0;
else return p = 1;
}
else {
dir = -2;
rev = 2;
return -1;
}
}
}
else if (dir == 2) {
if ((y[0] && !p) || (y[1] && p)) {
dir = 3;
return p;
}
else {
dir = 4;
rev = 1;
return -1;
}
}
else if (dir == 3) {
if ((y[0] && !p) || (y[1] && p)) {
dir = -2;
rev = 2;
return -1;
}
else {
dir = 1e18;
if (y[0]) return p = 0;
else return p = 1;
}
}
else if (dir == 4) {
dir = 5;
if (y[0]) return p = 0;
else return p = 1;
}
else if (dir == 5) {
if ((y[0] && !p) || (y[1] && p)) {
dir = 1e18;
if (y[0]) return p = 0;
else return p = 1;
}
else {
dir = -2;
return -1;
}
}
else if (dir == -2) {
dir = 1e18;
if (y[0]) return p = 0;
else return p = 1;
}
}
return -2;
}
}
void Init(int A, int B) {
if (!B) mode = 0;
else mode = 1;
}
int Move(std::vector<int> y) {
if (!mode) return CmodeA(y);
else return CmodeB(y);
}
Compilation message
Anthony.cpp: In function 'void {anonymous}::AmodeA()':
Anthony.cpp:18:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
18 | auto [u, w] = Q.front();
| ^
Anthony.cpp:20:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
20 | for (auto [v, x] : adj[u]) {
| ^
Anthony.cpp: In function 'void {anonymous}::dfs(long long int, long long int)':
Anthony.cpp:32:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
32 | for (auto [v, x] : adj[u]) {
| ^
Anthony.cpp: In function 'void {anonymous}::solve(long long int, long long int, long long int, long long int)':
Anthony.cpp:42:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
42 | for (auto [v, x] : adj[u]) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
15996 KB |
Output is correct |
2 |
Correct |
1 ms |
1308 KB |
Output is correct |
3 |
Correct |
25 ms |
15432 KB |
Output is correct |
4 |
Correct |
36 ms |
17192 KB |
Output is correct |
5 |
Correct |
35 ms |
17020 KB |
Output is correct |
6 |
Correct |
30 ms |
15736 KB |
Output is correct |
7 |
Correct |
31 ms |
15704 KB |
Output is correct |
8 |
Correct |
33 ms |
16496 KB |
Output is correct |
9 |
Correct |
33 ms |
16484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
15996 KB |
Output is correct |
2 |
Correct |
1 ms |
1308 KB |
Output is correct |
3 |
Correct |
25 ms |
15432 KB |
Output is correct |
4 |
Correct |
36 ms |
17192 KB |
Output is correct |
5 |
Correct |
35 ms |
17020 KB |
Output is correct |
6 |
Correct |
30 ms |
15736 KB |
Output is correct |
7 |
Correct |
31 ms |
15704 KB |
Output is correct |
8 |
Correct |
33 ms |
16496 KB |
Output is correct |
9 |
Correct |
33 ms |
16484 KB |
Output is correct |
10 |
Correct |
26 ms |
13916 KB |
Output is correct |
11 |
Correct |
28 ms |
13856 KB |
Output is correct |
12 |
Correct |
27 ms |
13756 KB |
Output is correct |
13 |
Correct |
27 ms |
14064 KB |
Output is correct |
14 |
Correct |
27 ms |
14196 KB |
Output is correct |
15 |
Correct |
30 ms |
14372 KB |
Output is correct |
16 |
Correct |
33 ms |
16904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
13368 KB |
Output is correct |
2 |
Correct |
1 ms |
1296 KB |
Output is correct |
3 |
Correct |
24 ms |
12928 KB |
Output is correct |
4 |
Correct |
34 ms |
14932 KB |
Output is correct |
5 |
Correct |
34 ms |
14968 KB |
Output is correct |
6 |
Correct |
27 ms |
13396 KB |
Output is correct |
7 |
Correct |
27 ms |
13424 KB |
Output is correct |
8 |
Correct |
31 ms |
14252 KB |
Output is correct |
9 |
Correct |
31 ms |
14184 KB |
Output is correct |
10 |
Correct |
30 ms |
13884 KB |
Output is correct |
11 |
Correct |
30 ms |
13876 KB |
Output is correct |
12 |
Correct |
31 ms |
14108 KB |
Output is correct |
13 |
Correct |
34 ms |
14476 KB |
Output is correct |
14 |
Correct |
31 ms |
14108 KB |
Output is correct |
15 |
Correct |
39 ms |
13992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
13368 KB |
Output is correct |
2 |
Correct |
1 ms |
1296 KB |
Output is correct |
3 |
Correct |
24 ms |
12928 KB |
Output is correct |
4 |
Correct |
34 ms |
14932 KB |
Output is correct |
5 |
Correct |
34 ms |
14968 KB |
Output is correct |
6 |
Correct |
27 ms |
13396 KB |
Output is correct |
7 |
Correct |
27 ms |
13424 KB |
Output is correct |
8 |
Correct |
31 ms |
14252 KB |
Output is correct |
9 |
Correct |
31 ms |
14184 KB |
Output is correct |
10 |
Correct |
30 ms |
13884 KB |
Output is correct |
11 |
Correct |
30 ms |
13876 KB |
Output is correct |
12 |
Correct |
31 ms |
14108 KB |
Output is correct |
13 |
Correct |
34 ms |
14476 KB |
Output is correct |
14 |
Correct |
31 ms |
14108 KB |
Output is correct |
15 |
Correct |
39 ms |
13992 KB |
Output is correct |
16 |
Correct |
24 ms |
11884 KB |
Output is correct |
17 |
Correct |
24 ms |
11892 KB |
Output is correct |
18 |
Correct |
26 ms |
11896 KB |
Output is correct |
19 |
Correct |
26 ms |
11896 KB |
Output is correct |
20 |
Correct |
28 ms |
12672 KB |
Output is correct |
21 |
Correct |
27 ms |
12560 KB |
Output is correct |
22 |
Correct |
31 ms |
14460 KB |
Output is correct |
23 |
Correct |
26 ms |
12144 KB |
Output is correct |
24 |
Correct |
26 ms |
12152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1556 KB |
Output is correct |
2 |
Correct |
1 ms |
1308 KB |
Output is correct |
3 |
Correct |
2 ms |
1868 KB |
Output is correct |
4 |
Correct |
2 ms |
1952 KB |
Output is correct |
5 |
Correct |
2 ms |
1564 KB |
Output is correct |
6 |
Correct |
2 ms |
1568 KB |
Output is correct |
7 |
Correct |
2 ms |
1560 KB |
Output is correct |
8 |
Correct |
2 ms |
1568 KB |
Output is correct |
9 |
Correct |
2 ms |
1564 KB |
Output is correct |
10 |
Correct |
2 ms |
1548 KB |
Output is correct |
11 |
Correct |
2 ms |
1568 KB |
Output is correct |
12 |
Correct |
1 ms |
1552 KB |
Output is correct |
13 |
Correct |
2 ms |
1568 KB |
Output is correct |
14 |
Correct |
1 ms |
1568 KB |
Output is correct |
15 |
Correct |
2 ms |
1568 KB |
Output is correct |
16 |
Correct |
2 ms |
1560 KB |
Output is correct |
17 |
Correct |
2 ms |
1560 KB |
Output is correct |
18 |
Correct |
2 ms |
1564 KB |
Output is correct |
19 |
Correct |
2 ms |
1560 KB |
Output is correct |
20 |
Correct |
2 ms |
1564 KB |
Output is correct |
21 |
Correct |
1 ms |
1564 KB |
Output is correct |
22 |
Correct |
2 ms |
1568 KB |
Output is correct |
23 |
Correct |
2 ms |
1568 KB |
Output is correct |
24 |
Correct |
2 ms |
1560 KB |
Output is correct |
25 |
Correct |
2 ms |
1572 KB |
Output is correct |
26 |
Correct |
2 ms |
1568 KB |
Output is correct |
27 |
Correct |
2 ms |
1560 KB |
Output is correct |
28 |
Correct |
2 ms |
1568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
11784 KB |
Output is correct |
2 |
Correct |
31 ms |
12900 KB |
Output is correct |
3 |
Correct |
1 ms |
1296 KB |
Output is correct |
4 |
Correct |
23 ms |
11348 KB |
Output is correct |
5 |
Correct |
34 ms |
14140 KB |
Output is correct |
6 |
Correct |
33 ms |
14128 KB |
Output is correct |
7 |
Correct |
28 ms |
13416 KB |
Output is correct |
8 |
Correct |
27 ms |
13444 KB |
Output is correct |
9 |
Correct |
37 ms |
14132 KB |
Output is correct |
10 |
Correct |
33 ms |
14140 KB |
Output is correct |
11 |
Correct |
31 ms |
14200 KB |
Output is correct |
12 |
Correct |
32 ms |
14208 KB |
Output is correct |
13 |
Correct |
33 ms |
14200 KB |
Output is correct |
14 |
Correct |
32 ms |
14136 KB |
Output is correct |
15 |
Correct |
33 ms |
14200 KB |
Output is correct |
16 |
Correct |
33 ms |
14196 KB |
Output is correct |
17 |
Correct |
32 ms |
13924 KB |
Output is correct |
18 |
Correct |
31 ms |
13892 KB |
Output is correct |
19 |
Correct |
32 ms |
13912 KB |
Output is correct |
20 |
Correct |
32 ms |
13876 KB |
Output is correct |
21 |
Correct |
34 ms |
13916 KB |
Output is correct |
22 |
Correct |
31 ms |
13952 KB |
Output is correct |
23 |
Correct |
27 ms |
11640 KB |
Output is correct |
24 |
Correct |
26 ms |
11648 KB |
Output is correct |
25 |
Correct |
28 ms |
12156 KB |
Output is correct |
26 |
Correct |
26 ms |
12156 KB |
Output is correct |
27 |
Correct |
31 ms |
12920 KB |
Output is correct |
28 |
Correct |
30 ms |
12852 KB |
Output is correct |
29 |
Correct |
28 ms |
12928 KB |
Output is correct |
30 |
Correct |
30 ms |
12852 KB |
Output is correct |
31 |
Correct |
31 ms |
11644 KB |
Output is correct |
32 |
Correct |
26 ms |
11640 KB |
Output is correct |
33 |
Correct |
26 ms |
11904 KB |
Output is correct |
34 |
Correct |
28 ms |
11896 KB |
Output is correct |
35 |
Correct |
28 ms |
12920 KB |
Output is correct |
36 |
Correct |
30 ms |
12920 KB |
Output is correct |
37 |
Correct |
28 ms |
12928 KB |
Output is correct |
38 |
Correct |
30 ms |
12920 KB |
Output is correct |
39 |
Correct |
28 ms |
12924 KB |
Output is correct |
40 |
Correct |
28 ms |
12912 KB |
Output is correct |
41 |
Correct |
30 ms |
13688 KB |
Output is correct |
42 |
Correct |
31 ms |
13688 KB |
Output is correct |
43 |
Correct |
32 ms |
13428 KB |
Output is correct |
44 |
Correct |
32 ms |
13436 KB |
Output is correct |
45 |
Correct |
30 ms |
13356 KB |
Output is correct |
46 |
Correct |
33 ms |
13440 KB |
Output is correct |
47 |
Correct |
28 ms |
12916 KB |
Output is correct |
48 |
Correct |
28 ms |
13108 KB |
Output is correct |
49 |
Correct |
28 ms |
12640 KB |
Output is correct |
50 |
Correct |
28 ms |
12924 KB |
Output is correct |
51 |
Correct |
27 ms |
11932 KB |
Output is correct |
52 |
Correct |
26 ms |
11900 KB |
Output is correct |
53 |
Correct |
26 ms |
11964 KB |
Output is correct |
54 |
Correct |
26 ms |
11860 KB |
Output is correct |
55 |
Correct |
32 ms |
11888 KB |
Output is correct |
56 |
Correct |
27 ms |
11904 KB |
Output is correct |
57 |
Correct |
27 ms |
11892 KB |
Output is correct |
58 |
Correct |
27 ms |
11888 KB |
Output is correct |
59 |
Correct |
26 ms |
11640 KB |
Output is correct |
60 |
Correct |
28 ms |
11936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
11676 KB |
Output is correct |
2 |
Correct |
28 ms |
12668 KB |
Output is correct |
3 |
Correct |
1 ms |
1292 KB |
Output is correct |
4 |
Correct |
23 ms |
11360 KB |
Output is correct |
5 |
Correct |
32 ms |
14192 KB |
Output is correct |
6 |
Correct |
35 ms |
14212 KB |
Output is correct |
7 |
Correct |
28 ms |
13432 KB |
Output is correct |
8 |
Correct |
28 ms |
13440 KB |
Output is correct |
9 |
Correct |
33 ms |
14200 KB |
Output is correct |
10 |
Correct |
35 ms |
14284 KB |
Output is correct |
11 |
Correct |
32 ms |
14200 KB |
Output is correct |
12 |
Correct |
32 ms |
14132 KB |
Output is correct |
13 |
Correct |
33 ms |
14220 KB |
Output is correct |
14 |
Correct |
33 ms |
14208 KB |
Output is correct |
15 |
Correct |
33 ms |
14204 KB |
Output is correct |
16 |
Correct |
34 ms |
14196 KB |
Output is correct |
17 |
Correct |
30 ms |
13940 KB |
Output is correct |
18 |
Correct |
31 ms |
13940 KB |
Output is correct |
19 |
Correct |
31 ms |
14256 KB |
Output is correct |
20 |
Correct |
33 ms |
14432 KB |
Output is correct |
21 |
Correct |
36 ms |
14400 KB |
Output is correct |
22 |
Correct |
30 ms |
14420 KB |
Output is correct |
23 |
Correct |
26 ms |
12104 KB |
Output is correct |
24 |
Correct |
25 ms |
12052 KB |
Output is correct |
25 |
Correct |
26 ms |
12364 KB |
Output is correct |
26 |
Correct |
26 ms |
12532 KB |
Output is correct |
27 |
Correct |
30 ms |
13380 KB |
Output is correct |
28 |
Correct |
30 ms |
13396 KB |
Output is correct |
29 |
Correct |
28 ms |
13400 KB |
Output is correct |
30 |
Correct |
30 ms |
13344 KB |
Output is correct |
31 |
Correct |
26 ms |
12116 KB |
Output is correct |
32 |
Correct |
26 ms |
12060 KB |
Output is correct |
33 |
Correct |
26 ms |
12364 KB |
Output is correct |
34 |
Correct |
28 ms |
12996 KB |
Output is correct |
35 |
Correct |
30 ms |
13408 KB |
Output is correct |
36 |
Correct |
28 ms |
13196 KB |
Output is correct |
37 |
Correct |
28 ms |
13364 KB |
Output is correct |
38 |
Correct |
28 ms |
13504 KB |
Output is correct |
39 |
Correct |
30 ms |
13396 KB |
Output is correct |
40 |
Correct |
30 ms |
13312 KB |
Output is correct |
41 |
Correct |
31 ms |
13960 KB |
Output is correct |
42 |
Correct |
34 ms |
13976 KB |
Output is correct |
43 |
Correct |
30 ms |
13892 KB |
Output is correct |
44 |
Correct |
31 ms |
13892 KB |
Output is correct |
45 |
Correct |
30 ms |
13908 KB |
Output is correct |
46 |
Correct |
30 ms |
13876 KB |
Output is correct |
47 |
Correct |
28 ms |
13108 KB |
Output is correct |
48 |
Correct |
28 ms |
12856 KB |
Output is correct |
49 |
Correct |
28 ms |
12864 KB |
Output is correct |
50 |
Correct |
28 ms |
13156 KB |
Output is correct |
51 |
Correct |
27 ms |
12380 KB |
Output is correct |
52 |
Correct |
27 ms |
12428 KB |
Output is correct |
53 |
Correct |
27 ms |
12440 KB |
Output is correct |
54 |
Correct |
28 ms |
12476 KB |
Output is correct |
55 |
Correct |
31 ms |
12536 KB |
Output is correct |
56 |
Correct |
27 ms |
12332 KB |
Output is correct |
57 |
Correct |
25 ms |
12360 KB |
Output is correct |
58 |
Correct |
27 ms |
12380 KB |
Output is correct |
59 |
Correct |
27 ms |
12384 KB |
Output is correct |
60 |
Correct |
28 ms |
12364 KB |
Output is correct |