This problem is in Contest(s) below:
Contest 1429:树的相关问题