CF1406C Link Cut Centroids

题目描述

#### 题意 给定一棵节点数为 $n$ 的树 , 删一条边然后加上一条边 , 使得该树的重心唯一 。(删掉的边和加上的边可以是同一条)

输入格式

第 $1$ 行一个正整数 $T$ , 表示有 $T$ 组测试数据 , 其中 $1\le T\le10^4$ 对于每组测试数据 。 第 $1$ 行一个正整数 $n$ , 表示该树有 $n$ 个节点 , 其中 $3\le n\le 10^5$ 。 第 $2$ 行到第 $n$ 行每行两个正整数 $x,y$ , 表示 $x$ 到 $y$ 有无一条无向边 , 其中 $1\le x,y\le n$ 。

输出格式

对于每一组测试数据 。 第 $1$ 行两个正整数 $x_1,y_1$ , 表示删的边的端点为 $x_1,y_1$ 。 第 $2$ 行两个正整数 $x_2,y_2$ , 表示连的边的端点为 $x_2,y_2$ 。 ### 限制与约定 对于每个测试点,保证 $\sum{n}\le10^5$。

说明/提示

Note that you can add the same edge that you cut. In the first test case, after cutting and adding the same edge, the vertex $ 2 $ is still the only centroid. In the second test case, the vertex $ 2 $ becomes the only centroid after cutting the edge between vertices $ 1 $ and $ 3 $ and adding the edge between vertices $ 2 $ and $ 3 $ .