#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(abs(a), abs(b));}
ll lcm(ll a, ll b){return abs(a) / gcd(a, b) * abs(b);}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ull mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
#include "Anthony.h"
namespace AnthonySub1{
vector<int> solve(int N, int M, int A, int B, vector<int> U, vector<int> V){
int n = N, m = M;
vector<vector<int>> graph(n);
for(int i = 0; i < m; ++i) {
int u = U[i], v = V[i];
graph[u].push_back(v);
graph[v].push_back(u);
}
vector<int> dis(n, 1e9 + 69);
deque<int> q; q.push_back(0);
dis[0] = 0;
while(q.size()){
int u = q.front(); q.pop_front();
for(int v: graph[u]) {
if (minimize(dis[v], dis[u] + 1))
q.push_back(v);
}
}
vector<int> ans;
for(int i = 0; i < m; ++i) {
int u = U[i], v = V[i];
if (dis[u] > dis[v]) swap(u, v);
ans.push_back(dis[u] % 3);
}
return ans;
}
}
namespace AnthonySub2{
const int N = 2e4 + 69;
vector<int> graph[N];
int h[N], color[N];
string s = "001011";
void dfs(int u, int p, int m){
vector<int> child;
for(int v: graph[u]) if (v != p) child.push_back(v);
if ((int)child.size() == 0) return;
if ((int)child.size() > 1){
for(int v: child) {
h[v] = h[u] + 1;
color[v] = color[u] ^ 1;
dfs(v, u, -1);
}
}
else{
int v = child[0];
if (m == -1) {
if (color[u] == 0) m = 1;
else m = 0;
}
h[v] = h[u] + 1;
color[v] = s[m] - '0';
dfs(v, u, (m + 1) % 6);
}
}
vector<int> solve(int N, int M, int A, int B, vector<int> U, vector<int> V){
int n = N, m = M;
for(int i = 0; i < m; ++i) {
int u = U[i], v = V[i];
graph[u].push_back(v);
graph[v].push_back(u);
}
dfs(0, 0, -1);
vector<int> ans;
for(int i = 0; i < m; ++i){
int u = U[i], v = V[i];
if (h[u] > h[v]) swap(u, v);
ans.push_back(color[v]);
}
return ans;
}
}
vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V){
if (A >= 3) return AnthonySub1::solve(N, M, A, B, U, V);
return AnthonySub2::solve(N, M, A, B, U, V);
}
// int main(void){
// ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
// return 0;
// }
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#include "Catherine.h"
int current_subtask = 0;
void Init(int A, int B){
if (A >= 3) current_subtask = 1;
else current_subtask = 2;
}
namespace CatherineSub1{
int solve(vector<int> y){
for(int i = 0; i < 3; ++i) {
if (y[i] > 0 && y[(i + 2) % 3] == 0)
return i;
}
return -1;
}
}
namespace CatherineSub2{
int last_edge = -1;
int correct_direction_found = 0;
string s;
string pattern = "001011";
bool check_pattern(string s){
for(int i = 0; i < 6; ++i){
reverse(1 + ALL(s)); reverse(ALL(s));
if (s == pattern) return true;
}
return false;
}
int solve_internal(vector<int> y){
int mi = min_element(ALL(y)) - y.begin(), ma = max_element(ALL(y)) - y.begin();
int deg = y[0] + y[1] + (last_edge != -1);
if (last_edge == -1){ // first time running
if (deg == 1){
correct_direction_found = 1;
return ma;
}
else if (deg > 2){
correct_direction_found = 1;
if (y[mi] == 0) assert(false);
return mi;
}
else{
for(int i = 0; i <= 1; ++i) while(y[i]--)
s.push_back('0' + i);
return s[1] - '0';
}
}
else{
if (correct_direction_found){
if (deg == 1){
assert(false); // this cant happen
return ma;
}
else if (deg > 2){
y[last_edge]++;
mi = min_element(ALL(y)) - y.begin();
return mi;
}
else{
return ma;
}
}
else{
if (deg == 1){
correct_direction_found = 1;
return -1;
}
else if (deg > 2){
correct_direction_found = 1;
y[last_edge]++;
mi = min_element(ALL(y)) - y.begin();
return mi;
}
else{
s.push_back(ma + '0');
if (s.size() == 6){
if (check_pattern(s)){
correct_direction_found = true;
return -1;
}
else{
correct_direction_found = true;
return ma;
}
}
return ma;
}
}
}
}
int solve(vector<int> y){ // wrapper
int ans = solve_internal(y);
if (ans != -1) last_edge = ans;
return ans;
}
}
int Move(vector<int> y){
if (current_subtask == 1) return CatherineSub1::solve(y);
return CatherineSub2::solve(y);
}
// int main(void){
// ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
// return 0;
// }
# | 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... |