AIZU ONLINE JUDGE Problem F: Marked Ancestor You are given a tree T that consists of N nodes. Each node...

Please Visit: http://ift.tt/1ajReyV



AIZU ONLINE JUDGE

Problem F: Marked Ancestor

You are given a tree T that consists of N nodes. Each node is numbered from 1 to N, and node 1 is always the root node of T. Consider the following two operations on T:

M v: (Mark) Mark node v.

Q v: (Query) Print the index of the nearest marked ancestor of node v which is nearest to it. Initially, only the root node is marked.

Your job is to write a program that performs a sequence of these operations on a given tree and calculates

the value that each Q operation will print. To avoid too large output file, your program is requested to

print the sum of the outputs of all query operations. Note that the judges confirmed that it is possible to

calculate every output of query operations in a given sequence.

http://ift.tt/W9fEv2

http://ift.tt/W9fEv3



AIZU ONLINE JUDGE







from Public RSS-Feed of Jeffery yuan. Created with the PIXELMECHANICS 'GPlusRSS-Webtool' at http://gplusrss.com http://ift.tt/1pGzOcR

via LifeLong Community

No comments:

Post a Comment