当前位置:网站首页>[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; } 边栏推荐
- 如何准备PMP新版大纲考试?
- 远程办公经验 | 社区征文
- Configuration software -- control import
- Ffmpe a small demo to understand 80% of common APIs
- QT custom control library creation
- Cartland number application
- 黑群晖DSM7.0.1物理机安装教程
- Nosqlzoo question brushing-1
- Uoj 553 [unr 4] caproic acid set [computational geometry (points in circle → points in half plane)]
- Uoj 551 [unr 4] campus stroll [good polynomial questions (FOG)]
猜你喜欢

@Jsonproperty annotation

【软件测试】这样的简历已经刷掉了90%的面试者

Miscellany C language

Summary of classic interview questions

RTMP protocol

2022 low voltage electrician test questions and online simulation test

【AtCoder2306】Rearranging(拓扑)

如果要存 IP 地址,用什么数据类型比较好?99%人都会答错!

QT interface nested movement based on qscrollarea
![[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
随机推荐
Djikstra solves the shortest circuit with negative weight
Pat class A by category
20200803 T3 my friends [divide and conquer NTT optimization recursion]
【AtCoder1984】Wide Swap (拓扑排序转化)
C memory alignment
pmp到底是什么?
20200727 T2 small w playing game [generating function (binomial inversion technique)]
SQLZOO刷题记录-3
[analysis of STL source code] summary notes (3): vector introduction
Compound RateModel合约解析
【POJ3691】DNA repair (AC自动机+DP)
C language to achieve minesweeping games
Seata的几种事务模式
Nim product
Wc2020 guessing game
MySQL设置管理员密码无法生效的案例一则
2022年熔化焊接与热切割考试练习题及答案
【HDU6357】Hills And Valleys(DP)
[Oracle database] mammy tutorial day04 Sorting Query
Post-processing of ffmpeg miscellaneous notes