This problem is in Contest(s) below:
Contest 1487:并查集
Contest 1318:初二寒假作业及最短路径、最小生成树、并查集