#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];
void dfs (int u, int chain = -1) {
if ((int) adj[u].size() == 2 && u != 0) {
if (chain == -1) {
chain = 1 - color[up_edge[u]];
} else {
chain++;
}
} else {
chain = -1;
}
for (int i : adj[u]) {
if (i != up_edge[u]) {
int v = other(i, u);
up_edge[v] = i;
color[i] = (chain == -1 ? 1 - color[up_edge[u]] : pattern[chain % 6]);
cout << edge_u[i] << " -- " << edge_v[i] << " (" << color[i] << ")\n";
dfs(v, chain);
}
}
}
void dfs () {
up_edge[0] = N; color[N] = 1;
dfs(0);
}
int dist[N_MAX];
void bfs () {
fill(dist, dist + N, -1);
up_edge[0] = N; color[N] = 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());
return X;
}
#include <bits/stdc++.h>
#include "Catherine.h"
using namespace std;
namespace {
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) {
cols.push_back((cnt_col[0] > 0 ? 0 : 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() == 6) {
int ok = -1;
for (int i = 0; i < 6; i++) {
if (cols[i] == 0 && cols[(i + 1) % 6] == 0) {
ok = (cols[(i + 2) % 6] != cols[(i + 3) % 6]);
break;
}
}
assert(ok != -1);
passed_test = true;
if (ok == false) {
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 |
27 ms |
15988 KB |
Output is correct |
2 |
Correct |
1 ms |
1300 KB |
Output is correct |
3 |
Correct |
26 ms |
15232 KB |
Output is correct |
4 |
Correct |
33 ms |
17012 KB |
Output is correct |
5 |
Correct |
34 ms |
16888 KB |
Output is correct |
6 |
Correct |
28 ms |
15728 KB |
Output is correct |
7 |
Correct |
27 ms |
15748 KB |
Output is correct |
8 |
Correct |
32 ms |
16500 KB |
Output is correct |
9 |
Correct |
36 ms |
16480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
15988 KB |
Output is correct |
2 |
Correct |
1 ms |
1300 KB |
Output is correct |
3 |
Correct |
26 ms |
15232 KB |
Output is correct |
4 |
Correct |
33 ms |
17012 KB |
Output is correct |
5 |
Correct |
34 ms |
16888 KB |
Output is correct |
6 |
Correct |
28 ms |
15728 KB |
Output is correct |
7 |
Correct |
27 ms |
15748 KB |
Output is correct |
8 |
Correct |
32 ms |
16500 KB |
Output is correct |
9 |
Correct |
36 ms |
16480 KB |
Output is correct |
10 |
Correct |
27 ms |
13648 KB |
Output is correct |
11 |
Correct |
28 ms |
13648 KB |
Output is correct |
12 |
Correct |
27 ms |
13568 KB |
Output is correct |
13 |
Correct |
30 ms |
13676 KB |
Output is correct |
14 |
Correct |
26 ms |
13932 KB |
Output is correct |
15 |
Correct |
32 ms |
14184 KB |
Output is correct |
16 |
Correct |
31 ms |
16512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
13428 KB |
Output is correct |
2 |
Correct |
1 ms |
1308 KB |
Output is correct |
3 |
Correct |
23 ms |
13008 KB |
Output is correct |
4 |
Correct |
33 ms |
14792 KB |
Output is correct |
5 |
Correct |
40 ms |
14784 KB |
Output is correct |
6 |
Correct |
30 ms |
13432 KB |
Output is correct |
7 |
Correct |
26 ms |
13428 KB |
Output is correct |
8 |
Correct |
28 ms |
14120 KB |
Output is correct |
9 |
Correct |
31 ms |
14200 KB |
Output is correct |
10 |
Correct |
28 ms |
13948 KB |
Output is correct |
11 |
Correct |
27 ms |
13980 KB |
Output is correct |
12 |
Correct |
27 ms |
13932 KB |
Output is correct |
13 |
Correct |
26 ms |
13772 KB |
Output is correct |
14 |
Correct |
30 ms |
14320 KB |
Output is correct |
15 |
Correct |
31 ms |
14164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
13428 KB |
Output is correct |
2 |
Correct |
1 ms |
1308 KB |
Output is correct |
3 |
Correct |
23 ms |
13008 KB |
Output is correct |
4 |
Correct |
33 ms |
14792 KB |
Output is correct |
5 |
Correct |
40 ms |
14784 KB |
Output is correct |
6 |
Correct |
30 ms |
13432 KB |
Output is correct |
7 |
Correct |
26 ms |
13428 KB |
Output is correct |
8 |
Correct |
28 ms |
14120 KB |
Output is correct |
9 |
Correct |
31 ms |
14200 KB |
Output is correct |
10 |
Correct |
28 ms |
13948 KB |
Output is correct |
11 |
Correct |
27 ms |
13980 KB |
Output is correct |
12 |
Correct |
27 ms |
13932 KB |
Output is correct |
13 |
Correct |
26 ms |
13772 KB |
Output is correct |
14 |
Correct |
30 ms |
14320 KB |
Output is correct |
15 |
Correct |
31 ms |
14164 KB |
Output is correct |
16 |
Correct |
25 ms |
11968 KB |
Output is correct |
17 |
Correct |
24 ms |
11952 KB |
Output is correct |
18 |
Correct |
25 ms |
11648 KB |
Output is correct |
19 |
Correct |
24 ms |
11632 KB |
Output is correct |
20 |
Correct |
26 ms |
12252 KB |
Output is correct |
21 |
Correct |
26 ms |
12152 KB |
Output is correct |
22 |
Correct |
28 ms |
14468 KB |
Output is correct |
23 |
Correct |
25 ms |
11888 KB |
Output is correct |
24 |
Correct |
25 ms |
11884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1316 KB |
Program didn't exit properly, or you printed something to stdout. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
4060 KB |
Program didn't exit properly, or you printed something to stdout. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
4064 KB |
Program didn't exit properly, or you printed something to stdout. |
2 |
Halted |
0 ms |
0 KB |
- |