CF1110G Tree-Tac-Toe(博弈论)

题面

传送门

题解

博弈论的前提是双方都是绝顶聪明的人

所以这种题目显然不是我应该做的

题解

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
int read(char *s){
	R int len=0;R char ch;while(((ch=getc())>'Z'||ch<'A'));
	for(s[++len]=ch;(ch=getc())>='A'&&ch<='Z';s[++len]=ch);
	return s[len+1]='\0',len;
}
const int N=1e6+5;
struct eg{int v,nx;}e[N<<1];int head[N],deg[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot,++deg[v];}
char s[N];int n;
void solve(){
	n=read(),tot=0;
	memset(head,0,4*(n+1)),memset(deg,0,4*(n+1));
	for(R int i=1,u,v;i<n;++i)u=read(),v=read(),add(u,v),add(v,u);
	read(s);
	if(n<3)return puts("Draw"),void();
	if(n==3){
		int cnt=(s[1]=='W')+(s[2]=='W')+(s[3]=='W');
		puts(cnt>1?"White":"Draw");
		return;
	}
	fp(i,1,n)if(s[i]=='W')head[++n]=0,add(i,n),add(n,i),deg[n]=3;
	int cc=0;
	fp(u,1,n)if(deg[u]>3)return puts("White"),void();
	else if(deg[u]==3){
		int cnt=0;
		go(u)cnt+=deg[v]>=2;
		if(cnt>=2)return puts("White"),void();
		++cc;
	}
	puts((cc==2&&(n&1))?"White":"Draw");
}
int main(){
//	freopen("testdata.in","r",stdin);
	int T=read();
	while(T--)solve();
	return 0;
}
posted @ 2019-04-03 17:21  bztMinamoto  阅读(262)  评论(0编辑  收藏  举报
Live2D