当前位置:网站首页>2022 Niu Ke Duo School Six B-Eezie and Pie (dfs)
2022 Niu Ke Duo School Six B-Eezie and Pie (dfs)
2022-08-07 03:39:00 【AC__dream】
Title: 
Sample input:
101 2twenty threetwenty four3 54 64 71 88 98 100 0 1 2 2 5 3 1 0 2Sample output:
6 6 2 3 1 1 1 2 1 1Title:Given a rooted tree, the root is 1, each node can be its 0 ~ 𝑑[𝑖] level ancestor contribution1 value.Find the final value of each point.
Analysis: For each child node, you can first find its first ancestor node v that cannot contribute, and reduce loss[v] by 1, then above vThe ancestor node of the node cannot get the contribution of the node, so that is to say, the loss can be uploaded, then the meaning of loss[v] means that theThe number of child nodes in the subtree rooted by v that cannot contribute to v.So we can get that the final value of each node is the number of nodes in the subtree with him as the root minus the number of child nodes in the subtree with him as the root that cannot contribute to him, that is, cnt[]+loss[]
We can directly find several levels of parent nodes of each node in the dfs process, so that we can find the d[i]+1 level father, which is theThe first ancestor node of the node that cannot contribute, the complexity of the query is log level, so the total complexity is nlogn level.
See code for details:
#include#include#include#include#include 边栏推荐
猜你喜欢

如何快速开发app?小程序+插件少不了

“go1.15.3“ does not match go tool version “go1.13.8“

微信小程序的在线学习每日签到打卡 项目源码介绍

Dangerous, please replace BeanUtils in the code immediately

Wireless Video Surveillance of Construction Site Industrial Grade Wireless Router Application

Implement caching mechanism using soft references

Some basic concepts and methods of proxy ip (updating...)

STM32F103ZET6突然下载不了程序??

项目管理知识点

集合与迭代器
随机推荐
JUC源码学习笔记4——原子类,CAS,Volatile内存屏障,缓存伪共享与UnSafe相关方法
About DevExpress settings record
[transfer] swig
梦想照进现实|CSDN 实体奖牌 第二期
5G/4G water resource remote control terminal
精彩回顾|云原生 Meetup 广州站
How to create a replica database
STM32F103ZET6突然下载不了程序??
2333. 最小差值平方和-排序加二分查找,力扣c语言题解
阅读笔记——RetinaFace: Single-stage Dense Face Localisation in the Wild
计讯物联水环境综合管控方案,打造水清绿岸的生活环境
Wechat applet online learning daily check-in and punch-in project source code introduction
Codeforces Round #810 (Div. 2)D~A
Auto.js实现自动化取消公众号
聊聊字典那些事
wpf中TreeView的滚动条
Small application container in the application of integrated online government service platform
SaaS服务平台软件是什么?
【诡秘之主】源质篇
1002: please three seven writing a maximum number of C language