TopCoder SRM 662 Div1 Medium ExactTree

これは自力では解けず。 http://community.topcoder.com/stat?c=problem_statement&pm=13857