#include <bits/stdc++.h>
using namespace std;
#include "Anthony.h"
int A, B;
const int seq[6] = { 0, 0, 1, 0, 1, 1 };
vector<int> Mark(int N, int M, int _A, int _B, vector<int> U, vector<int> V)
{
	A = _A;
	B = _B;
	vector<vector<pair<int, int>>> adj(N);
	for(int i = 0; i < M; i++)
	{
		adj[U[i]].push_back({ V[i], i });
		adj[V[i]].push_back({ U[i], i });
	}
	vector<int> res(M, -1);
	queue<pair<int, int>> q;
	vector<bool> vit(N);
	q.push({ 0, 0 });
	vit[0] = 1;
	while(!q.empty())
	{
		auto [x, d] = q.front();
		q.pop();
		int nd;
		if(B == 0)
			nd = (d + 1) % 3;
		else
		{
			int sz = (int)adj[x].size();
			if(x != 0)
				sz--;
			if(sz > 1)
			{
				if(seq[(d + 5) % 6])
					d = 0;
				else
					d = 2;
			}
			nd = (d + 1) % 6;
		}
		for(auto [y, i] : adj[x])
		{
			if(res[i] == -1)
			{
				if(B == 0)
					res[i] = d;
				else
					res[i] = seq[d];
			}
			if(!vit[y])
			{
				vit[y] = 1;
				q.push({ y, nd });
			}
		}
	}
	return res;
}
#include <bits/stdc++.h>
using namespace std;
#include "Catherine.h"
int A, B;
const int seq[6] = { 0, 0, 1, 0, 1, 1 };
void Init(int _A, int _B)
{
	A = _A;
	B = _B;
}
bool fin;
int pre = -2;
vector<int> his;
bool can[6];
int solve(int y0, int y1)
{
	int s = y0 + y1;
	int deg = s;
	if(pre != -2)
		deg++;
	int nx = y0 ? 0 : 1;
	if(deg >= 3)
	{
		fin = 1;
		return y1 > 1 || pre == 1 ? 0 : 1;
	}
	if(deg == 1)
	{
		fin = 1;
		if(pre == -2)
			return nx;
		return -1;
	}
	if(fin)
	{
		assert(s == 1);
		return nx;
	}
	assert(deg == 2);
	if(pre == -2)
	{
		if(y0 == 2)
			can[1] = 1;
		else if(y1 == 2)
			can[5] = 1;
		else
			can[0] = can[3] = 1;
		his.push_back(nx);
		return nx;
	}
	assert(s == 1);
	his.push_back(nx);
	if((int)his.size() < 4)
		return nx;
	fin = 1;
	for(int i = 0; i < 6; i++)
	{
		if(!can[i])
			continue;
		bool ok = 1;
		for(int j = 0; j < 4; j++)
			if(seq[(i + j) % 6] != his[j])
				ok = 0;
		if(ok)
			return -1;
	}
	return nx;
}
int Move(vector<int> y)
{
	if(B == 0)
	{
		if(y[0] && !y[2])
			return 0;
		if(y[1])
			return 1;
		return 2;
	}
	int r = solve(y[0], y[1]);
	if(r != -1)
		pre = r;
	return r;
}
| # | 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... |