HBC244831巨木之森,深度优先搜索(DFS),搜索Mr.Bridge and Tree Planting题解

痛心疾首 算法基础篇 67 0
想要成为编程高手?那就来试试全网最全C++题库,让您在练习中快速成长。
Mr.Bridge wanted to plant his seeds into his garden,he asked his firend Mr.house for some advice.Mr.house is an expert in biology,he found that these seeds can grow into trees,and they will grow up in this way:. At first each tree has one node,which is called "growing node".Every time it grows,there will be a new node appears above the growing node and connect with the growing node by an edge.Then the growing node move up to the new node.But sometimes strange things can happen to some trees: its growing node move to the node under it.We called it "growing drop".Mr.Bridge was happy to know how the tree grows,and he planted. i -th tree and wondered how many nodes are in its growing node's subtree.(If node. Every time when a tree drops there will be at least one node that is not in its growing node's subtree.Please help Mr.Bridge to count the number of nodes.

Mr.Bridge has got many seeds,wow! Mr.Bridge wanted to plant his seeds into his garden,he asked his firend Mr.house for some advice. Mr.house is an expert in biology,he found that these seeds can grow into trees,and they will grow up in this way: At first each tree has one node,which is called "growing node". Every time it grows,there will be a new node appears above the growing node and connect with the growing node by an edge.Then the growing node move up to the new node. But sometimes strange things can happen to some trees: its growing node move to the node under it.We called it "growing drop". Mr.Bridge was happy to know how the tree grows,and he planted n n seeds in a row,numbered from 1 1 to n n. Then m m days has pasted. Everyday one of the following things happened: 1.All trees which numbered from l l to r r growed. 2.All trees which numbered from l l to r r "growing droped". 3.Mr.Bridge came to watch them happily.He got close to the i i -th tree and wondered how many nodes are in its growing node's subtree.(If node A A can be reached from node B B only by moving up,we call "node A A is in node B B 's subtree") Every time when a tree drops there will be at least one node that is not in its growing node's subtree. Please help Mr.Bridge to count the number of nodes.

HBC244831巨木之森,深度优先搜索(DFS),搜索Mr.Bridge and Tree Planting题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断学习,不断挑战,才能在编程领域中脱颖而出!全网最全C++题库,助您成为编程高手!

标签: HBC244831巨木之森 深度优先搜索(DFS) 搜索Mr.Bridge and Tree Planting题解