#include <bits/stdc++.h>
#include "Anthony.h"
using namespace std;
#define pii pair<int, int>
#define F first
#define S second
static const int maxn = 2e4 + 10;
static int n, m, a, b,
seq[] = {0, 1, 0, 1, 1, 0},
dist[maxn];
static vector<pii> adj[maxn];
static vector<int> x;
void mark1(){
fill(dist, dist + n, -1);
queue<int> q;
q.push(0); dist[0] = 0;
while (!q.empty()){
int v = q.front(); q.pop();
for (auto k : adj[v]){
int u = k.F, i = k.S;
if (dist[u] != -1) continue;
dist[u] = dist[v] + 1;
q.push(u);
}
}
}
void mark2(int v, int p, int last_idx){
int cnt_children = 0, next_idx;
for (auto k : adj[v]){
int u = k.F, i = k.S;
if (u != p) cnt_children++;
}
if (cnt_children <= 1){ // line
next_idx = (last_idx == 5 ? 0 : last_idx + 1);
}
else{ // multiple children
next_idx = (seq[last_idx] == 0 ? 1 : 0);
}
for (auto k : adj[v]){
int u = k.F, i = k.S;
if (u == p) continue;
x[i] = seq[next_idx];
mark2(u, v, next_idx);
}
}
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;
x.resize(m, -1);
for (int i = 0; i < m; i++){
adj[U[i]].push_back({V[i], i});
adj[V[i]].push_back({U[i], i});
}
if (a >= 3){ // type 1: bfs tree; 2 -> 1 -> 0
mark1();
for (int v = 0; v < n; v++){
for (auto k : adj[v]){
int u = k.F, i = k.S;
if (dist[u] < dist[v]) x[i] = dist[u] % 3;
else x[i] = dist[v] % 3;
}
}
}
else{
mark2(0, 0, 0);
// for (int v = 0; v < n; v++){
// cout << v << endl;
// for (auto k : adj[v]){
// cout << "to " << k.F << ": " << x[k.S] << endl;
// }
// cout << endl;
// cout << endl;
// }
}
return x;
}
#include <bits/stdc++.h>
#include "Catherine.h"
using namespace std;
#define pii pair<int, int>
#define F first
#define S second
static const int maxn = 2e4 + 10;
static int n, m, a, b, last = -1,
seq[] = {0, 1, 0, 1, 1, 0};
static bool is_type_1, found_direction = false;
static vector<int> bruh;
void Init(int A, int B){
a = A, b = B;
if (a >= 3) is_type_1 = true;
else is_type_1 = false;
}
int Move(vector<int> y){
if (is_type_1){
// for (auto k : y) cout << k << ' '; cout << endl;
for (int i = 0; i < a; i++){
int next = (i == 0 ? 2 : i - 1);
if (y[i] > 0 && y[next] == 0) return i;
}
return -1;
}
else{
vector<int> x = y;
if (last != -1) x[last]++;
int cnt = x[0] + x[1];
if (found_direction){
if (cnt >= 3){ // not line
y[last]++;
last = (x[0] < x[1] ? 0 : 1);
}
else{ // is line
last = (y[0] ? 0 : 1);
}
return last;
}
else{
if (cnt >= 3){ // not line
found_direction = true;
last = (x[0] < x[1] ? 0 : 1);
return (x[last] == y[last] ? last : -1);
}
else{
if (last == -1){ // first one
if (cnt == 1){
found_direction = true;
last = (x[0] ? 0 : 1);
}
else if (y[0] == 2){
bruh.push_back(0);
last = 0;
}
else if (y[0] == 1){
bruh.push_back(0);
last = 1;
}
else if (y[0] == 0){
bruh.push_back(1);
last = 1;
}
// cout << last << endl;
bruh.push_back(last);
return last;
}
if (bruh.size() < 4){
if (cnt == 1){
found_direction = true;
last = bruh.back();
return -1;
}
last = (y[0] ? 0 : 1);
bruh.push_back(last);
return last;
}
else{ // completed
if (cnt == 1){
found_direction = true;
last = bruh.back();
return -1;
}
bruh.push_back(y[0] ? 0 : 1);
// for (auto k : bruh) cout << k << ' '; cout << endl;
bool is_right = false;
for (int start = 0; start < 6; start++){
bool pos = true;
for (int i = 0; i < 5; i++){
if (bruh[i] != seq[(start - i + 6) % 6]) pos = false;
}
if (pos) is_right = true;
}
if (is_right){
// cout << "right" << endl;
found_direction = true;
last = (y[0] ? 0 : 1);
return last;
}
else{
// cout << "bruh" << endl;
bruh.pop_back();
found_direction = true;
last = bruh.back();
return -1;
}
}
}
}
}
return -1;
}
Compilation message
Anthony.cpp: In function 'void mark1()':
Anthony.cpp:23:26: warning: unused variable 'i' [-Wunused-variable]
23 | int u = k.F, i = k.S;
| ^
Anthony.cpp: In function 'void mark2(int, int, int)':
Anthony.cpp:34:22: warning: unused variable 'i' [-Wunused-variable]
34 | int u = k.F, i = k.S;
| ^
Catherine.cpp:10:15: warning: 'm' defined but not used [-Wunused-variable]
10 | static int n, m, a, b, last = -1,
| ^
Catherine.cpp:10:12: warning: 'n' defined but not used [-Wunused-variable]
10 | static int n, m, a, b, last = -1,
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
15536 KB |
Output is correct |
2 |
Correct |
1 ms |
1024 KB |
Output is correct |
3 |
Correct |
25 ms |
14832 KB |
Output is correct |
4 |
Correct |
36 ms |
16456 KB |
Output is correct |
5 |
Correct |
35 ms |
16616 KB |
Output is correct |
6 |
Correct |
27 ms |
15304 KB |
Output is correct |
7 |
Correct |
28 ms |
15272 KB |
Output is correct |
8 |
Correct |
44 ms |
16008 KB |
Output is correct |
9 |
Correct |
33 ms |
15976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
15536 KB |
Output is correct |
2 |
Correct |
1 ms |
1024 KB |
Output is correct |
3 |
Correct |
25 ms |
14832 KB |
Output is correct |
4 |
Correct |
36 ms |
16456 KB |
Output is correct |
5 |
Correct |
35 ms |
16616 KB |
Output is correct |
6 |
Correct |
27 ms |
15304 KB |
Output is correct |
7 |
Correct |
28 ms |
15272 KB |
Output is correct |
8 |
Correct |
44 ms |
16008 KB |
Output is correct |
9 |
Correct |
33 ms |
15976 KB |
Output is correct |
10 |
Correct |
26 ms |
13412 KB |
Output is correct |
11 |
Correct |
25 ms |
13372 KB |
Output is correct |
12 |
Correct |
26 ms |
13504 KB |
Output is correct |
13 |
Correct |
25 ms |
13436 KB |
Output is correct |
14 |
Correct |
27 ms |
13612 KB |
Output is correct |
15 |
Correct |
28 ms |
14064 KB |
Output is correct |
16 |
Correct |
33 ms |
16116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
13160 KB |
Output is correct |
2 |
Correct |
1 ms |
1024 KB |
Output is correct |
3 |
Correct |
22 ms |
12676 KB |
Output is correct |
4 |
Correct |
33 ms |
14300 KB |
Output is correct |
5 |
Correct |
31 ms |
14436 KB |
Output is correct |
6 |
Correct |
26 ms |
13160 KB |
Output is correct |
7 |
Correct |
31 ms |
13088 KB |
Output is correct |
8 |
Correct |
30 ms |
13664 KB |
Output is correct |
9 |
Correct |
30 ms |
13724 KB |
Output is correct |
10 |
Correct |
28 ms |
13396 KB |
Output is correct |
11 |
Correct |
28 ms |
13472 KB |
Output is correct |
12 |
Correct |
28 ms |
13592 KB |
Output is correct |
13 |
Correct |
28 ms |
13416 KB |
Output is correct |
14 |
Correct |
32 ms |
13904 KB |
Output is correct |
15 |
Correct |
30 ms |
13816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
13160 KB |
Output is correct |
2 |
Correct |
1 ms |
1024 KB |
Output is correct |
3 |
Correct |
22 ms |
12676 KB |
Output is correct |
4 |
Correct |
33 ms |
14300 KB |
Output is correct |
5 |
Correct |
31 ms |
14436 KB |
Output is correct |
6 |
Correct |
26 ms |
13160 KB |
Output is correct |
7 |
Correct |
31 ms |
13088 KB |
Output is correct |
8 |
Correct |
30 ms |
13664 KB |
Output is correct |
9 |
Correct |
30 ms |
13724 KB |
Output is correct |
10 |
Correct |
28 ms |
13396 KB |
Output is correct |
11 |
Correct |
28 ms |
13472 KB |
Output is correct |
12 |
Correct |
28 ms |
13592 KB |
Output is correct |
13 |
Correct |
28 ms |
13416 KB |
Output is correct |
14 |
Correct |
32 ms |
13904 KB |
Output is correct |
15 |
Correct |
30 ms |
13816 KB |
Output is correct |
16 |
Correct |
24 ms |
11640 KB |
Output is correct |
17 |
Correct |
25 ms |
11488 KB |
Output is correct |
18 |
Correct |
27 ms |
11380 KB |
Output is correct |
19 |
Correct |
24 ms |
11472 KB |
Output is correct |
20 |
Correct |
27 ms |
12224 KB |
Output is correct |
21 |
Correct |
26 ms |
11888 KB |
Output is correct |
22 |
Correct |
30 ms |
13936 KB |
Output is correct |
23 |
Correct |
25 ms |
11616 KB |
Output is correct |
24 |
Correct |
24 ms |
11568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1292 KB |
Output is correct |
2 |
Correct |
1 ms |
1084 KB |
Output is correct |
3 |
Correct |
2 ms |
1300 KB |
Output is correct |
4 |
Correct |
2 ms |
1296 KB |
Output is correct |
5 |
Correct |
2 ms |
1296 KB |
Output is correct |
6 |
Correct |
2 ms |
1404 KB |
Output is correct |
7 |
Correct |
2 ms |
1288 KB |
Output is correct |
8 |
Correct |
2 ms |
1340 KB |
Output is correct |
9 |
Correct |
2 ms |
1292 KB |
Output is correct |
10 |
Correct |
2 ms |
1288 KB |
Output is correct |
11 |
Correct |
2 ms |
1288 KB |
Output is correct |
12 |
Correct |
2 ms |
1296 KB |
Output is correct |
13 |
Correct |
2 ms |
1288 KB |
Output is correct |
14 |
Correct |
2 ms |
1288 KB |
Output is correct |
15 |
Correct |
2 ms |
1288 KB |
Output is correct |
16 |
Correct |
2 ms |
1296 KB |
Output is correct |
17 |
Correct |
2 ms |
1288 KB |
Output is correct |
18 |
Correct |
2 ms |
1288 KB |
Output is correct |
19 |
Correct |
2 ms |
1288 KB |
Output is correct |
20 |
Correct |
2 ms |
1336 KB |
Output is correct |
21 |
Correct |
2 ms |
1288 KB |
Output is correct |
22 |
Correct |
2 ms |
1288 KB |
Output is correct |
23 |
Correct |
2 ms |
1288 KB |
Output is correct |
24 |
Correct |
2 ms |
1288 KB |
Output is correct |
25 |
Correct |
2 ms |
1340 KB |
Output is correct |
26 |
Correct |
2 ms |
1284 KB |
Output is correct |
27 |
Correct |
2 ms |
1296 KB |
Output is correct |
28 |
Correct |
2 ms |
1284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
11340 KB |
Output is correct |
2 |
Correct |
29 ms |
12356 KB |
Output is correct |
3 |
Correct |
2 ms |
1032 KB |
Output is correct |
4 |
Correct |
25 ms |
10988 KB |
Output is correct |
5 |
Correct |
31 ms |
13628 KB |
Output is correct |
6 |
Correct |
31 ms |
13536 KB |
Output is correct |
7 |
Correct |
28 ms |
12572 KB |
Output is correct |
8 |
Correct |
26 ms |
12644 KB |
Output is correct |
9 |
Correct |
31 ms |
13556 KB |
Output is correct |
10 |
Correct |
30 ms |
13576 KB |
Output is correct |
11 |
Correct |
30 ms |
13476 KB |
Output is correct |
12 |
Correct |
30 ms |
13600 KB |
Output is correct |
13 |
Correct |
38 ms |
13488 KB |
Output is correct |
14 |
Correct |
31 ms |
13596 KB |
Output is correct |
15 |
Correct |
30 ms |
13532 KB |
Output is correct |
16 |
Correct |
30 ms |
13608 KB |
Output is correct |
17 |
Correct |
28 ms |
13268 KB |
Output is correct |
18 |
Correct |
30 ms |
13140 KB |
Output is correct |
19 |
Correct |
34 ms |
13256 KB |
Output is correct |
20 |
Correct |
28 ms |
13168 KB |
Output is correct |
21 |
Correct |
28 ms |
13220 KB |
Output is correct |
22 |
Correct |
27 ms |
13332 KB |
Output is correct |
23 |
Correct |
28 ms |
11252 KB |
Output is correct |
24 |
Correct |
26 ms |
11232 KB |
Output is correct |
25 |
Correct |
24 ms |
11624 KB |
Output is correct |
26 |
Correct |
24 ms |
12096 KB |
Output is correct |
27 |
Correct |
27 ms |
12452 KB |
Output is correct |
28 |
Correct |
27 ms |
12460 KB |
Output is correct |
29 |
Correct |
27 ms |
12456 KB |
Output is correct |
30 |
Correct |
27 ms |
12392 KB |
Output is correct |
31 |
Correct |
26 ms |
11696 KB |
Output is correct |
32 |
Correct |
24 ms |
11312 KB |
Output is correct |
33 |
Correct |
25 ms |
12016 KB |
Output is correct |
34 |
Correct |
25 ms |
11616 KB |
Output is correct |
35 |
Correct |
27 ms |
12276 KB |
Output is correct |
36 |
Correct |
27 ms |
12784 KB |
Output is correct |
37 |
Correct |
28 ms |
12740 KB |
Output is correct |
38 |
Correct |
33 ms |
12304 KB |
Output is correct |
39 |
Correct |
28 ms |
12728 KB |
Output is correct |
40 |
Correct |
31 ms |
12280 KB |
Output is correct |
41 |
Correct |
39 ms |
12940 KB |
Output is correct |
42 |
Correct |
35 ms |
13348 KB |
Output is correct |
43 |
Correct |
30 ms |
12848 KB |
Output is correct |
44 |
Correct |
31 ms |
12988 KB |
Output is correct |
45 |
Correct |
30 ms |
13320 KB |
Output is correct |
46 |
Correct |
30 ms |
13364 KB |
Output is correct |
47 |
Correct |
27 ms |
12600 KB |
Output is correct |
48 |
Correct |
27 ms |
12532 KB |
Output is correct |
49 |
Correct |
28 ms |
12736 KB |
Output is correct |
50 |
Correct |
27 ms |
12712 KB |
Output is correct |
51 |
Correct |
24 ms |
11872 KB |
Output is correct |
52 |
Correct |
26 ms |
11852 KB |
Output is correct |
53 |
Correct |
26 ms |
11900 KB |
Output is correct |
54 |
Correct |
26 ms |
11900 KB |
Output is correct |
55 |
Correct |
25 ms |
11768 KB |
Output is correct |
56 |
Correct |
26 ms |
11888 KB |
Output is correct |
57 |
Correct |
28 ms |
12160 KB |
Output is correct |
58 |
Correct |
35 ms |
11984 KB |
Output is correct |
59 |
Correct |
26 ms |
11836 KB |
Output is correct |
60 |
Correct |
26 ms |
11892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
11240 KB |
Output is correct |
2 |
Correct |
27 ms |
12724 KB |
Output is correct |
3 |
Correct |
1 ms |
1028 KB |
Output is correct |
4 |
Correct |
24 ms |
11392 KB |
Output is correct |
5 |
Correct |
39 ms |
13800 KB |
Output is correct |
6 |
Correct |
31 ms |
13868 KB |
Output is correct |
7 |
Correct |
26 ms |
13108 KB |
Output is correct |
8 |
Correct |
34 ms |
13040 KB |
Output is correct |
9 |
Correct |
33 ms |
13928 KB |
Output is correct |
10 |
Correct |
33 ms |
13928 KB |
Output is correct |
11 |
Correct |
31 ms |
14036 KB |
Output is correct |
12 |
Correct |
34 ms |
13980 KB |
Output is correct |
13 |
Correct |
31 ms |
13908 KB |
Output is correct |
14 |
Correct |
32 ms |
13916 KB |
Output is correct |
15 |
Correct |
34 ms |
14016 KB |
Output is correct |
16 |
Correct |
31 ms |
13960 KB |
Output is correct |
17 |
Correct |
30 ms |
13648 KB |
Output is correct |
18 |
Correct |
30 ms |
13652 KB |
Output is correct |
19 |
Correct |
28 ms |
13688 KB |
Output is correct |
20 |
Correct |
30 ms |
13692 KB |
Output is correct |
21 |
Correct |
30 ms |
13736 KB |
Output is correct |
22 |
Correct |
34 ms |
13680 KB |
Output is correct |
23 |
Correct |
25 ms |
11632 KB |
Output is correct |
24 |
Correct |
25 ms |
11728 KB |
Output is correct |
25 |
Correct |
25 ms |
12096 KB |
Output is correct |
26 |
Correct |
25 ms |
12144 KB |
Output is correct |
27 |
Correct |
33 ms |
12856 KB |
Output is correct |
28 |
Correct |
27 ms |
12920 KB |
Output is correct |
29 |
Correct |
33 ms |
12912 KB |
Output is correct |
30 |
Correct |
36 ms |
12856 KB |
Output is correct |
31 |
Correct |
25 ms |
11748 KB |
Output is correct |
32 |
Correct |
25 ms |
11732 KB |
Output is correct |
33 |
Correct |
25 ms |
12160 KB |
Output is correct |
34 |
Correct |
24 ms |
12096 KB |
Output is correct |
35 |
Correct |
28 ms |
12692 KB |
Output is correct |
36 |
Correct |
32 ms |
12740 KB |
Output is correct |
37 |
Correct |
27 ms |
12728 KB |
Output is correct |
38 |
Correct |
27 ms |
12740 KB |
Output is correct |
39 |
Correct |
36 ms |
12660 KB |
Output is correct |
40 |
Correct |
30 ms |
12684 KB |
Output is correct |
41 |
Correct |
28 ms |
13324 KB |
Output is correct |
42 |
Correct |
28 ms |
13236 KB |
Output is correct |
43 |
Correct |
28 ms |
13268 KB |
Output is correct |
44 |
Correct |
35 ms |
13364 KB |
Output is correct |
45 |
Correct |
38 ms |
13372 KB |
Output is correct |
46 |
Correct |
37 ms |
13308 KB |
Output is correct |
47 |
Correct |
27 ms |
12540 KB |
Output is correct |
48 |
Correct |
27 ms |
12612 KB |
Output is correct |
49 |
Correct |
30 ms |
12488 KB |
Output is correct |
50 |
Correct |
27 ms |
12744 KB |
Output is correct |
51 |
Correct |
26 ms |
11764 KB |
Output is correct |
52 |
Correct |
30 ms |
11876 KB |
Output is correct |
53 |
Correct |
26 ms |
11824 KB |
Output is correct |
54 |
Correct |
30 ms |
11792 KB |
Output is correct |
55 |
Correct |
25 ms |
11832 KB |
Output is correct |
56 |
Correct |
28 ms |
11800 KB |
Output is correct |
57 |
Correct |
25 ms |
11968 KB |
Output is correct |
58 |
Correct |
24 ms |
11892 KB |
Output is correct |
59 |
Correct |
27 ms |
11876 KB |
Output is correct |
60 |
Correct |
25 ms |
11832 KB |
Output is correct |