Universal Cup Judging System

Universal Cup

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100 Difficulty: [show]
Statistics

广州,又称羊城,是一座有着 2200 多年历史的活力大都市。作为古代海上丝绸之路的重要起点,自秦汉以来一直是国际贸易的重要港口。 在刚刚过去的一年里,第十五届全国运动会在广州圆满落幕。运动员们拼搏进取的精神在这座城市依然蓬勃发展。

图 1:广州白云国际机场的“大湾鸡”

现在,你和你的队友计划在广州旅游。有 $n$ 个景点你想去游览。此外,你计划在广州停留 $m$ 天。 景点之间存在 $n-1$ 条边(关系)。每条边连接两个景点,表示它们在历史或风景上紧密相关。此外,任意两个不同的景点都可以通过一条或多条边互相到达,这意味着这些边构成了一棵树。 你决定每个景点恰好游览一次。设 $b_i$ 为游览第 $i$ 个景点的日期。你的计划必须满足:

  • 你在第 $i$ 天预订的酒店在景点 $a_i$ 附近。这意味着你必须在第 $i$ 天游览景点 $a_i$。换句话说,对所有 $i = 1, 2, \dots, m$,都有 $b_{a_i} = i$。
  • 对于每个景点 $i$($1 \le i \le n$),将其与同一天(第 $b_i$ 天)游览的其他景点相连的边数,不少于与任何其他日期游览的景点相连的边数。换句话说,对于每个 $u = 1, 2, \dots, n$ 和每个 $t = 1, 2, \dots, m$,都必须满足 $\sum_{(u,v) \in E} [b_v = b_u] \ge \sum_{(u,v) \in E} [b_v = t]$,其中 $E$ 是所有边的集合。

那么,现在制定你的计划吧!构造任意一组满足上述条件的 $b_1, b_2, \dots, b_n$,或者说明这是不可能实现的。

输入格式

每个测试用例包含多个测试数据。第一行包含一个整数 $t$($1 \le t \le 10^5$),表示测试数据的数量。接下来是测试数据的描述。

每个测试数据的第一行包含两个整数 $n, m$($1 \le m \le n \le 10^5$,$1 < \sum n, \sum m \le 10^6$),分别表示景点的数量和停留的天数。 第二行包含 $m$ 个整数 $a_1, a_2, \dots, a_m$($1 \le a_i \le n$,当 $i < j$ 时 $a_i \ne a_j$),表示你必须在第 $i$ 天游览景点 $a_i$。 接下来的 $n-1$ 行,每行包含两个整数 $u_i, v_i$($1 \le u_i, v_i \le n$),表示一条边。

输出格式

对于每个测试数据,如果你无法制定出有效的计划,输出 NO。 否则,输出两行。第一行包含单词 YES,第二行包含 $b_1, b_2, \dots, b_n$($1 \le b_i \le m$),表示你的计划。 如果存在多个有效的答案,你可以输出其中任意一个。

样例

输入格式 1

4
1 1
1
4 2
2 3
1 2
2 3
3 4
3 2
1 3
1 2
2 3
6 3
1 2 4
1 2
2 3
1 4
4 5
1 6

输出格式 1

YES
1
YES
1 1 2 2
NO
YES
1 2 2 3 3 1

说明

图 2:测试数据 4 的样例示意图

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.