[ACM] 2012-Multi-University Training 6th Contest

occur
tree
weight

#1

Could anybody give me some hint to solve this problem?

http://acm.tju.edu.cn/acm/showp3923.html