当前位置:网站首页>[atcoder2307] tree game
[atcoder2307] tree game
2022-06-11 07:37:00 【CaptainHarryChen】
The question
There is a tree. , Each node has A[i] A stone ,A Start putting a piece on any node , Then from A Start ,A,B Take turns
Subtract the number of stone nodes of the current chess piece 1
Move the chess pieces to the adjacent nodes
No operator can input
seek A Start putting the pieces where you want to win .
Answer key
nature : A chess piece will not go where there are more stones than itself ( If you go this way , The other party can come back , One chess piece is missing , The other side is more than themselves , We cannot win the war of attrition ...)
Then we can directly simulate the calculation NP state
Enumerate a point as a starting point , then dfs Traverse , Find out all NP
Code
#include<cstdio> #include<vector> #include<algorithm> using namespace std; const int MAXN=3005; int n,A[MAXN]; vector<int> adj[MAXN]; bool st[MAXN]; void dfs(int u,int fa=0) {
st[u]=false; A[u]--; for(int i=0;i<(int)adj[u].size();i++) {
int v=adj[u][i]; if(v==fa||A[v]>A[u]) continue; dfs(v,u); if(st[v]==false) {
st[u]=true; break; } } A[u]++; } int main() {
scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&A[i]); 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); } for(int i=1;i<=n;i++) {
dfs(i); if(st[i]) printf("%d ",i); } puts(""); return 0; } 边栏推荐
- Aiop introduction
- 【AtCoder1981】Shorten Diameter(图论思维)
- VIM common commands
- 【AtCoder2305】Decrementing(博弈)
- Bidirectional linked list simple template (pointer version)
- Regular Expression Matching
- Ffmpeg extraction package format extracts AAC and customizes adtc header to realize arbitrary frame decoding
- C language to write a calculator calculation logic
- A correction book full of sad tears
- nosqlzoo刷题-1
猜你喜欢

Flask页面的分页
![[IOT] intelligent hardware: how to obtain the WiFi signal strength of hardware products](/img/85/5766d8269391820b5e142178530657.png)
[IOT] intelligent hardware: how to obtain the WiFi signal strength of hardware products

2. Graduated from this course, and the bank has outsourced testing work for more than 4 months. Talk about some real feelings
![[Oracle database] mammy tutorial day02 use of database management tool sqlplus](/img/f2/8f6f74a62427ebfb4c805c1e9b3352.png)
[Oracle database] mammy tutorial day02 use of database management tool sqlplus

软件测试周刊(第75期):唯有平视,才能看见真实的自己。
![[codeforces1019e] raining season](/img/8e/4a96954ee7dae5f81eaae05b5a075b.png)
[codeforces1019e] raining season

Simple configuration of vscade

Paging of the flask page
![[analysis of STL source code] summary notes (6): Design of iterator and magical traits](/img/57/eaf02e880d205c5912f353609c9520.png)
[analysis of STL source code] summary notes (6): Design of iterator and magical traits

C language inherits memory management mechanism (unfinished)
随机推荐
pmp到底是什么?
【AtCoder1984】Wide Swap (拓扑排序转化)
Nim product
Implementation of stack (C language)
[Oracle database] mammy tutorial day04 Sorting Query
【集群】LVS+keepalived高可用集群
【IoT】智能硬件:如何获取硬件产品的wifi信号强度
big. Js-- use / instance
学 SQL 必须了解的10个高级概念
【Oracle 数据库】奶妈式教程day03 排序查询
[software testing] 90% of the interviewers have been brushed out of such resumes
群晖DS918创建m.2 固态硬盘SSD读写缓存
【AtCoder2307】Tree Game(博弈)
Uoj 553 [unr 4] caproic acid set [computational geometry (points in circle → points in half plane)]
[analysis of STL source code] summary notes (6): Design of iterator and magical traits
.NET C#基础(6):命名空间 - 有名字的作用域
Sdl-4 PCM playback
【AtCoder2305】Decrementing(博弈)
MySQL设置管理员密码无法生效的案例一则
2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]