This problem is in Contest(s) below:
Contest 1429:树的相关问题
Contest 1331:最小生成树专题
Contest 1492:最小生成树专题
Contest 1355:最靓的仔
Contest 1497:YC_2021