当前位置:网站首页>[atcoder2376] black and white tree (game)
[atcoder2376] black and white tree (game)
2022-06-11 07:37:00 【CaptainHarryChen】
The question
A and B Dye the nodes on the tree in turn ,A Every time you choose the untainted spots, dye them white ,B Every time you choose to dye the untainted dots into black , Finally, if all white is adjacent to black , be B - , otherwise A - . Both sides adopt the optimal strategy , seek A Win or lose B - .
Answer key
A First, select the parent of the leaf node u, be B Only leaf nodes can be selected ( Otherwise, after the leaf nodes are dyed white , Can never be next to black ), therefore , If there is u There are more than two leaf nodes , be A - ;
And then delete u, be u Father v, If v No child nodes ,v It becomes a new leaf node ,A You can continue with the previous operation ,B Always be passive .
When there are two situations ,A A winning
- The current node u Contains two or more leaf nodes
- if u Root , And u All child nodes of are dyed white ( Then you can dye yourself white )
dfs Just deal with one side .
Code
#include<cstdio> #include<cstring> #include<vector> #include<algorithm> using namespace std; const int MAXN=100005; int N; vector<int> adj[MAXN]; int col[MAXN]; bool dfs(int u,int f) {
if(adj[u].size()==1U) {
col[u]=0;// Marked as leaf node return false; } int cnt[2]={
0}; for(int i=0;i<(int)adj[u].size();i++) {
int v=adj[u][i]; if(v==f) continue; if(dfs(v,u)) return true; cnt[col[v]]++; } if(cnt[0]>=2) return true;// Leaf node is greater than or equal to 2 if(f==0&&(int)adj[u].size()==cnt[1]) return true;// At present u Root ,u All child nodes of are white if(cnt[0]) col[u]=1;// If there are leaf nodes , This one is dyed white else col[u]=0;// All the child nodes of this point are dyed white ( Deleted ), At present u Become a leaf node return false; } int main() {
scanf("%d",&N); for(int i=1;i<N;i++) {
int u,v; scanf("%d%d",&u,&v); adj[u].push_back(v); adj[v].push_back(u); } if(N==2) puts("Second"); else {
bool ans; for(int i=1;i<=N;i++) if(adj[i].size()>1U) {
ans=dfs(i,0); break; } puts(ans?"First":"Second"); } return 0; } 边栏推荐
- 2022 low voltage electrician test questions and online simulation test
- [software testing] 90% of the interviewers have been brushed out of such resumes
- Post-processing of ffmpeg miscellaneous notes
- 学 SQL 必须了解的10个高级概念
- 模线性方程组(中国剩余定理+通用解法)
- If you want to save an IP address, what data type is better? 99% of people will answer wrong!
- 20200730 T3 small B farm [maximum perimeter empty rectangle (monotone stack + line segment tree)] & "ROI 2017 day 2" learning track
- 【Oracle 数据库】奶妈式教程day04 排序查询
- Implementation of queue (C language)
- 【AtCoder2000】Leftmost Ball (DP+组合数)
猜你喜欢

Summary of classic interview questions
![[Oracle database] mammy tutorial day03 Sorting Query](/img/ea/24c9495a2ef4f1786f7b7852bde321.png)
[Oracle database] mammy tutorial day03 Sorting Query
![20200803 T3 my friends [divide and conquer NTT optimization recursion]](/img/35/01201e3136e3dd5cd562a0481f1ee9.jpg)
20200803 T3 my friends [divide and conquer NTT optimization recursion]

After 4 years of naked resignation from the test, the test post of 15K interview was rubbed on the ground, and the result made me collapse and cry

Use of wordcloud

2022低压电工操作证考试题模拟考试平台操作

Sdl-2 thread logic

Paging of the flask page
![[STL source code analysis] summary note (2): overview of containers](/img/66/60fba564ae6020dfb503c7fdf78529.jpg)
[STL source code analysis] summary note (2): overview of containers
![20200730 T3 small B farm [maximum perimeter empty rectangle (monotone stack + line segment tree)] &](/img/90/99356e679a52890a0b88068d082bbe.jpg)
20200730 T3 small B farm [maximum perimeter empty rectangle (monotone stack + line segment tree)] & "ROI 2017 day 2" learning track
随机推荐
Implementation of stack (C language)
模线性方程组(中国剩余定理+通用解法)
Deux diplômés, la Banque a externalisé le travail d'essai pendant plus de quatre mois. Parler de vrais sentiments...
Raspberry pie builds a full-featured NAS server (07): manage your library & read as you please
A case in which the MySQL administrator password cannot take effect
Compound ratemodel contract analysis
[STL source code analysis] summary notes (12): functors and adapters
如果要存 IP 地址,用什么数据类型比较好?99%人都会答错!
What exactly is PMP?
【Oracle 数据库】奶妈式教程day04 排序查询
2022.5.30-6.5 AI行业周刊(第100期):三年时光
2022 low voltage electrician operation certificate test question simulation test platform operation
Rabin-Miller素数测试
【AtCoder2387】+/- Rectangle
远程办公经验 | 社区征文
【CodeForces1019E】Raining season(边分治+斜率优化)
Classes and objects (Part 2)
JVM tuning
Rabin Miller prime test
Sdl-3 YUV playback