连接冲突AI (CI翻译)
A tree is a connected graph without cycles. Define an independent set of a tree as a set of vertices such that no two distinct vertices in the set are directly connected by an edge in the tree. A maximum independent set is an independent set that contains the largest possible number of vertices.
树是一个连通且无环的图。树的独立集是指一个顶点集合,其中任意两个不同的顶点在树中都没有边直接相连。最大独立集是指包含顶点数最多的独立集。AI (CI翻译)
Given a forest of $k$ trees, we want to add $k-1$ edges to unite the forest into a single tree so as to maximize the size of the maximum independent set of the resulting tree. Please find the additional edges.
给定一个由 $k$ 棵树组成的森林,我们希望添加 $k-1$ 条边,将森林连接成一棵树,并使所得树的最大独立集的大小尽可能大。请找出需要添加的边。AI (CI翻译)
If there are several valid answers, you may output any of them.
如果存在多个合法答案,你可以输出其中任意一个。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个测试包含多组测试用例。第一行包含测试用例数 $t$ ($1 \le t \le 10^4$)。接下来是各组测试用例的描述。AI (CI翻译)
The first line of each test case contains a single integer $k$ ($2 \le k \le 2 \cdot 10^5$) — the number of trees in the forest.
每组测试用例的第一行包含一个整数 $k$ ($2 \le k \le 2 \cdot 10^5$) —— 森林中树的数量。AI (CI翻译)
This is followed by a description of each of the $k$ trees, which are numbered $1, 2, \ldots, k$ in order:
接下来依次描述这 $k$ 棵树,它们按顺序编号为 $1, 2, \ldots, k$:AI (CI翻译)
The first line contains a single integer $n$ ($1\le n \le 2 \cdot 10^5$) — the size of the tree. The vertices of the tree are numbered with integers from $1$ to $n$.
第一行包含一个整数 $n$ ($1\le n \le 2 \cdot 10^5$) —— 这棵树的顶点数。树的顶点用从 $1$ 到 $n$ 的整数编号。AI (CI翻译)
Each of the next $n-1$ lines contains two integers $u$ and $v$ ($1 \le u,v \le n$, $u \ne v$), denoting an edge between vertices $u$ and $v$. It is guaranteed that the given edges form a tree.
接下来的 $n-1$ 行中,每行包含两个整数 $u$ 和 $v$ ($1 \le u,v \le n$, $u \ne v$),表示顶点 $u$ 和 $v$ 之间有一条边。保证给出的边构成一棵树。AI (CI翻译)
It is guaranteed that the sum of $k$ over all test cases does not exceed $2 \cdot 10^5$.
保证所有测试用例的 $k$ 之和不超过 $2 \cdot 10^5$。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output $k-1$ lines; each line contains four integers $t_1, v_1, t_2, v_2$, denoting an edge between $(t_1,v_1)$ and $(t_2,v_2)$ that is added to the original graph.
对于每组测试用例,输出 $k-1$ 行;每行包含四个整数 $t_1, v_1, t_2, v_2$,表示向原图中添加一条连接 $(t_1,v_1)$ 和 $(t_2,v_2)$ 的边。AI (CI翻译)
Note that we number all $k$ trees from $1$ to $k$ in the order in which they appear in the input data. For any tree $i$ ($1\le i \le k$), if it contains $n$ nodes, then its nodes are numbered from $1$ to $n$. The $j$-th node in this tree is denoted by $(i,j)$.
注意,我们按照这 $k$ 棵树在输入中出现的顺序,将它们从 $1$ 到 $k$ 编号。对于任意一棵树 $i$ ($1\le i \le k$),若它包含 $n$ 个顶点,则其顶点从 $1$ 到 $n$ 编号。这棵树中的第 $j$ 个顶点记为 $(i,j)$。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, the graph has two vertices and no edge; adding an edge between these two nodes is the only way to turn the graph into a tree.
在第一组测试用例中,图中有两个顶点,没有边;在这两个顶点之间添加一条边是将图变成一棵树的唯一方式。AI (CI翻译)
In the second test case, we can add an edge between the only vertex $1$ of tree $2$ and one of the vertices $1$, $2$, and $3$ of tree $1$.
在第二组测试用例中,我们可以在树 $2$ 中唯一的顶点 $1$ 与树 $1$ 中的顶点 $1$、$2$、$3$ 之一之间添加一条边。AI (CI翻译)
- add edge
$(2,1)-(1,1)$, the size of a maximum independent set of the resulting tree is 3. - add edge
$(2,1)-(1,2)$, the size of a maximum independent set of the resulting tree is 2. - add edge
$(2,1)-(1,3)$, the size of a maximum independent set of the resulting tree is 2.
- 添加边
$(2,1)-(1,1)$,所得树的最大独立集的大小为 3。 - 添加边
$(2,1)-(1,2)$,所得树的最大独立集的大小为 2。 - 添加边
$(2,1)-(1,3)$,所得树的最大独立集的大小为 2。
So, we choose the edge $(2,1)-(1,1)$ since it is optimal.
因此,我们选择边 $(2,1)-(1,1)$,因为它是最优的。AI (CI翻译)
样例
2
2
1
1
2
3
1 2
1 3
1
2 1 1 1
2 1 1 1
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。