Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---- Military Problem ----
- There are n officers in Berland Army.
- It's an undirected Map.
- A special case that the commander has no sub commander.
- - Construction of the army-
- A tree consisting of n vertices, in which vertex u corresponds to officer u.
- (ui,ki) where ui us some officer, and ki is a positive integer.
- To process, the i-th query imagine how a command from ui
- spreads to the subordinates of ui.
- Typical DFS (depth-first search) algorithm is used here.
- INPUT
- FIRST LINE:
- n-1 integers p2,p3,…,pn (1≤pi<i),
- where pi is the index of the direct superior of the officer having the index i.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement