CF748F.Santa Clauses and a Soccer Championship
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The country Treeland consists of n cities connected with n - 1 bidirectional roads in such a way that it's possible to reach every city starting from any other city using these roads. There will be a soccer championship next year, and all participants are Santa Clauses. There are exactly 2_k_ teams from 2_k_ different cities.
During the first stage all teams are divided into k pairs. Teams of each pair play two games against each other: one in the hometown of the first team, and the other in the hometown of the other team. Thus, each of the 2_k_ cities holds exactly one soccer game. However, it's not decided yet how to divide teams into pairs.
It's also necessary to choose several cities to settle players in. Organizers tend to use as few cities as possible to settle the teams.
Nobody wants to travel too much during the championship, so if a team plays in cities u and v, it wants to live in one of the cities on the shortest path between u and v (maybe, in u or in v). There is another constraint also: the teams from one pair must live in the same city.
Summarizing, the organizers want to divide 2_k_ teams into pairs and settle them in the minimum possible number of cities m in such a way that teams from each pair live in the same city which lies between their hometowns.
国家 Treeland 由 n 座城市组成,这些城市通过 n−1 条双向道路相连,使得任意两座城市之间均可通过这些道路互相到达(即构成一棵树)。明年将举办一场足球锦标赛,所有参赛者均为圣诞老人。恰好有 2k 支队伍,分别来自 2k 个不同的城市。
在第一阶段,所有队伍被划分为 k 对。每对中的两支队伍需相互进行两场比赛:一场在第一支队伍所在的城市举行,另一场在第二支队伍所在的城市举行。因此,这 2k 座城市中每座城市恰好举办一场比赛。然而,目前尚未确定如何将队伍配对。
此外,还需选定若干城市作为球员的住宿地。主办方希望尽可能减少所选城市的数量。
没有人希望在锦标赛期间过多地旅行。因此,若一支队伍的比赛城市为 u 和 v,则该队希望住在 u 与 v 之间最短路径上的某座城市(可以是 u 或 v 本身)。还有一项额外约束:同一对中的两支队伍必须住在同一座城市。
综上所述,主办方希望将 2k 支队伍划分为 k 对,并以最少可能的城市数量 m 安排住宿,使得每一对中的两支队伍均住在其各自家乡城市之间的某一座城市中。
输入格式
The first line of input contains two integers n and k (2 ≤ n ≤ 2·105, 2 ≤ 2_k_ ≤ n) — the number of cities in Treeland and the number of pairs of teams, respectively.
The following n - 1 lines describe roads in Treeland: each of these lines contains two integers a and b (1 ≤ a, b ≤ n, a ≠ b) which mean that there is a road between cities a and b. It's guaranteed that there is a path between any two cities.
The last line contains 2_k_ distinct integers _c_1, _c_2, ..., c_2_k (1 ≤ c__i ≤ n), where c__i is the hometown of the i-th team. All these numbers are distinct.
输入的第一行包含两个整数 n 和 k(2 ≤ n ≤ 2⋅105,2 ≤ 2k ≤ n),分别表示 Treeland 中的城市数量以及队伍对的数量。
接下来的 n−1 行描述 Treeland 中的道路:每行包含两个整数 a 和 b(1 ≤ a, b ≤ n,a = b),表示城市 a 与城市 b 之间有一条道路。保证任意两座城市之间均存在路径。
最后一行包含 2k 个互不相同的整数 c1,c2,…,c2k(1 ≤ ci ≤ n),其中 ci 表示第 i 支队伍的家乡。所有这些数互不相同。
输出格式
The first line of output must contain the only positive integer m which should be equal to the minimum possible number of cities the teams can be settled in.
The second line should contain m distinct numbers _d_1, _d_2, ..., d__m (1 ≤ d__i ≤ n) denoting the indices of the cities where the teams should be settled.
The k lines should follow, the j-th of them should contain 3 integers u__j, v__j and x__j, where u__j and v__j are the hometowns of the j-th pair's teams, and x__j is the city they should live in during the tournament. Each of the numbers _c_1, _c_2, ..., c_2_k should occur in all u__j's and v__j's exactly once. Each of the numbers x__j should belong to {_d_1, _d_2, ..., d__m}.
If there are several possible answers, print any of them.
输出的第一行必须包含唯一的一个正整数 m,该值应等于队伍所能安置的城市的最少数量。
第二行应包含 m 个互不相同的整数 d1,d2,...,dm(其中 1≤di≤n),表示队伍在锦标赛期间应被安置的城市编号。
接下来应输出 k 行,其中第 j 行包含三个整数 uj、vj 和 xj,其中 uj 和 vj 分别为第 j 对队伍的家乡城市,而 xj 是该对队伍在锦标赛期间应居住的城市。所有 c1,c2,...,c2k 这些数必须在全部 uj 和 vj 中恰好各出现一次。每个 xj 必须属于集合 {d1,d2,...,dm}。
若存在多种可能的答案,输出任意一种即可。
输入输出样例
输入#1
6 2 1 2 1 3 2 4 2 5 3 6 2 5 4 6
输出#1
1 2 5 4 2 6 2 2
说明/提示
In the first test the orginizers can settle all the teams in the city number 2. The way to divide all teams into pairs is not important, since all requirements are satisfied anyway, because the city 2 lies on the shortest path between every two cities from {2, 4, 5, 6}.
在第一个测试中,主办方可以将所有队伍安排在编号为 2 的城市。将所有队伍划分为若干对的方式并不重要,因为无论如何划分,所有要求均能得到满足——这是因为城市 2 位于集合 {2, 4, 5, 6} 中任意两座城市之间的最短路径上。
输入解题思路,AI测评打分。不知道怎么写?