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题解