| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 1183100 | mertbbm | 길고양이 (JOI20_stray) | C++20 | 0 ms | 0 KiB | 
#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
namespace{
	vector<pii>adj[200005];
	vector<int>ret;
	int s2[6]={0,0,1,1,0,1};
	
	void dfs(int index, int par, int cur, bool amos){
		//cerr << index << " " << amos << " visit" << endl;
		for(auto it:adj[index]){
			if(it.first==par) continue;
			if(adj[index].size()>2){
				if(amos){
					//place 0
					//cerr << it.second << " it.second" << endl; 
					ret[it.second]=0;
					dfs(it.first,index,1,0);
				}
				else{
					//place 1 
					//cerr << it.second << " 1it.second" << endl;
					ret[it.second]=1;
					dfs(it.first,index,0,1);
				}
			}
			else{
				ret[it.second]=s2[cur%6];
				dfs(it.first,index,(cur+1)%6,ret[it.second]);
			}
		}
	}
	
	struct DSU{
		vector<int>e;
		void init(int n){
			e=vector<int>(n,-1);
		}
		
		int get(int x){
			return e[x]<0?x:e[x]=get(e[x]);
		}
		
		bool unite(int x, int y){
			x=get(x); y=get(y);
			if(x==y) return 1;
			if(e[x]>e[y]) swap(x,y);
			e[x]+=e[y];
			e[y]=x;
			return 0;
		}
	};
}
vector<int>Mark(int n, int m, int a, int b, vector<int>u, vector<int>v){
	::ret.resize(m,-1);
	::DSU dsu;
	dsu.init(n+5);
	for(int x=0;x<m;x++){
		if(dsu.unite(u[x],v[x])){
			ret[x]=2;
			continue;
		}
		::adj[u[x]].push_back({v[x],x});
		::adj[v[x]].push_back({u[x],x});
	}
	::dfs(0,-1,0,1);
	//cerr << "done" << endl;
	//for(int y=0;y<(int)::ret.size();y++){
		//cout << ::ret[y] << " ";
	//}
	//cout << "\n";
	return ::ret;
}
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
namespace{
	int color=0;
	int s[6]={1,0,1,1,0,0};
	vector<int>cur;
	bool amos=false;
}
void Init(int A, int B){
	::color=A;
}
int Move(vector<int>y){
	//show4(y,y);
	vector<int>go;
	vector<int>one;
	for(int x=0;x<2;x++){
		if(y[x]==1) one.push_back(x);
		//if(y[x]) go.push_back(x);
		for(int i=0;i<y[x];i++) go.push_back(x);
	}
	
	if(cur.empty()&&go.size()!=1){
		::amos=true;
	}
	if(one.empty()){
		if(!go.empty()){
			::cur.push_back(go.back());
			return go.back();
		}
		amos=false;
		return -1;
	}
	else if(one.size()==1){
		::cur.push_back(one[0]);
		if(amos&&::cur.size()==4){
			bool valid=false;
			for(int y=0;y<6;y++){
				bool ok=true;
				for(int i=0;i<4;i++){
					if(::s[(y+i)%6]!=cur[i]) ok=false;
				}
				valid|=ok;
			}
			amos=false;
			if(!valid){
				return -1;
			}
		}
		return one[0];
	}
	::cur.push_back(!cur.back());
	return ::cur.back();
}
