#include "Anthony.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
namespace {
int FunctionExample(int i, int A) {
return i % A;
}
}
vector<int> Mark(int n, int m, int A, int B,
std::vector<int> U, std::vector<int> V) {
vector<int> X(m);
vector<vector<pii>> g(n);
for(int i = 0; i < m; ++i){
g[U[i]].pb({V[i], i});
g[V[i]].pb({U[i], i});
}
vi vis(n + 1);
vis[0] = 1;
queue<int> q;
vi par(n + 1);
vi col(n + 1);
q.push(0);
while(!q.empty()){
int v = q.front(); q.pop();
for(auto [u, idx]: g[v]){
if(!vis[u]){
par[u] = v;
q.push(u);
col[u] = (col[v] + 1) % min(A, 3);
vis[u] = 1;
}
}
}
if(A >= 3){
for(int i = 0; i < n; ++i){
for(auto [u, idx]: g[i]){
if(col[u] == col[i]){
X[idx] = col[u];
}else{
vi v; v.pb(col[i]); v.pb(col[u]);
sort(all(v));
if(v[0] != 0){
X[idx] = 1;
}else if(v[1] != 1){
X[idx] = 2;
}else{
X[idx] = 0;
}
}
}
}
}else{
for(int i = 0; i < n; ++i){
for(auto [u, idx]: g[i]){
if(u == par[i]){
X[idx] = col[i];
}
}
}
}
// for(int i = 0 ; i< m; ++i){
// cerr << U[i] << ' ' << V[i] << ' ' << X[i] << '\n';
// }
return X;
}
/* Author : Mychecksdead */
#include "Catherine.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
namespace {
int last_color = -1;
int A, B;
bool found = false;
int up = 0;
stack<int> st;
} // namespace
void Init(int A, int B) {
::A = A;
::B = B;
}
int Move(std::vector<int> y) {
if(A >= 3){
vi v;
if(y[0]) v.pb(0);
if(y[1]) v.pb(1);
if(y[2]) v.pb(2);
if(v.size() == 1) return v[0];
if(v[0] != 0) return 1;
if(v[1] != 1) return 2;
return 0;
}
vi v = y; // lazyness to change
if(last_color == -1){ // beginning
if(v[0] + v[1] == 1){ // leaf
found = true;
return last_color = v[0] > 0 ? 0 : 1;
}
if(v[0] + v[1] == 2){ // mid chain
up++;
last_color = v[0] > 0 ? 0 : 1;
st.push(last_color);
return last_color;
}
found = true; // deg(v) >= 3, we know where to go, so found = true
return v[0] == 1 ? 0 : 1;
}
if(v[0] + v[1] == 0){ // hit leaf
st.pop();
found = true;
return -1;
}
if(v[0] + v[1] == 1){ // middle of a chain
if(found){
return last_color = v[0] > 0 ? 0 : 1;
}else{
// check whether we reached the hash
return last_color = v[0] > 0 ? 0 : 1; // nothing for now
}
}
// if we hit a deg(v) >= 3, we will see same thing more than once, or we're in the right direction, so keep alternating.
if(v[0] == 0){
found = true;
last_color = 0;
return -1;
}
if(v[1] == 0){
found = true;
last_color = 1;
return -1;
}
found = true;
last_color = 1 - last_color;
return last_color;
}
# | 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... |