This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Anthony.h"
#include <vector>
#include <queue>
using namespace std;
namespace Anthony_7 {
int N, M;
vector<int> U, V, X;
vector<vector<int>> adj;
void dfs(int u, int id, int path_order = -1)
{
if (adj[u].size() == 1) return;
if (adj[u].size() == 2) {
int nxt = id ^ adj[u][0] ^ adj[u][1];
if (!~path_order) path_order = X[id];
path_order = (path_order + 1) % 6;
X[nxt] = (path_order == 1 || path_order == 4 || path_order == 5);
return dfs(U[nxt] ^ V[nxt] ^ u, nxt, path_order);
}
int x = X[id] ^ 1;
for (int nxt : adj[u]) if (nxt != id) {
X[nxt] = x;
dfs(U[nxt] ^ V[nxt] ^ u, nxt);
}
}
vector<int> mark(int _N, int _M, int A, int B, vector<int> _U, vector<int> _V)
{
N = _N, M = _M, U = move(_U), V = move(_V);
X.resize(M);
adj.assign(N, vector<int>(0));
for (int i = 0; i < M; ++i) {
adj[U[i]].push_back(i);
adj[V[i]].push_back(i);
}
for (int id : adj[0]) {
X[id] = 0;
dfs(U[id] ^ V[id], id);
}
return X;
}
}
namespace Anthony_4 {
int N, M;
vector<int> U, V, X;
vector<vector<int>> adj;
vector<int> mark(int _N, int _M, int A, int B, vector<int> _U, vector<int> _V)
{
N = _N, M = _M, U = move(_U), V = move(_V);
X.resize(M);
adj.assign(N, vector<int>(0));
for (int i = 0; i < M; ++i) {
adj[U[i]].push_back(i);
adj[V[i]].push_back(i);
}
vector<int> dist(N, N + 5);
queue<int> qu;
qu.push(0), dist[0] = 0;
while (!qu.empty()) {
int u = qu.front(); qu.pop();
for (int id : adj[u]) {
int v = U[id] ^ V[id] ^ u;
if (dist[u] + 1 < dist[v]) {
dist[v] = dist[u] + 1;
qu.push(v);
}
}
}
for (int i = 0; i < M; ++i) {
X[i] = min(dist[U[i]], dist[V[i]]) % 3;
}
return X;
}
}
vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V)
{
if (A == 2) return Anthony_7::mark(N, M, A, B, U, V);
else return Anthony_4::mark(N, M, A, B, U, V);
}
#include "Catherine.h"
#include <vector>
#include <cassert>
#include <numeric>
#include <iostream>
using namespace std;
namespace Catherine_7 {
bool confused = true;
int last_col = -1;
vector<int> prev_cols;
void init(int _A, int _B)
{
confused = true;
last_col = -1;
prev_cols.clear();
}
int move(vector<int> Y)
{
int deg = accumulate(Y.begin(), Y.end(), int(last_col != -1));
if (deg != 2) {
if (~last_col) ++Y[last_col];
confused = false;
for (int i = 0; i < (int) Y.size(); ++i) {
if (Y[i] == 1) {
if (i == last_col) return -1;
return last_col = i;
}
}
assert(0);
}
if (not confused) { // wait up
assert(~last_col);
for (int i = 0; i < (int) Y.size(); ++i) {
if (Y[i] == 1) {
return last_col = i;
}
}
assert(0);
}
for (int i = 0; i < (int) Y.size(); ++i) {
for (int j = 0; j < Y[i]; ++j) {
prev_cols.push_back(i);
}
}
cerr << "prev ";
for (int x : prev_cols) cerr << x << ' ';
cerr << endl;
for (int i = 0; i < (int) prev_cols.size() - 1; ++i) if (prev_cols[i] == prev_cols[i + 1]) {
if (i - 2 >= 0) {
confused = false;
if (prev_cols[i - 2] == 0) return last_col = prev_cols[prev_cols.size() - 2], -1;
else return last_col = prev_cols.back();
}
if (i + 3 < (int) prev_cols.size()) {
confused = false;
if (prev_cols[i + 3] == 1) return last_col = prev_cols[prev_cols.size() - 2], -1;
else return last_col = prev_cols.back();
}
}
assert((int) prev_cols.size() < 5);
return last_col = prev_cols.back();
}
}
namespace Catherine_4 {
void init(int A, int B) {}
int move(vector<int> Y)
{
if (!Y[2] && Y[0]) return 0;
if (!Y[0] && Y[1]) return 1;
if (!Y[1] && Y[2]) return 2;
assert(0);
}
}
void Init(int A, int B)
{
if (A == 2) Catherine_7::init(A, B);
else Catherine_4::init(A, B);
}
int Move(vector<int> Y)
{
if ((int) Y.size() == 2) return Catherine_7::move(Y);
else return Catherine_4::move(Y);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |