Universal Cup Judging System

Universal Cup

시간 제한: 2 s 메모리 제한: 1024 MB 총점: 100 난이도: [표시]
통계

HSFZPC 2026 May 4th, 2026 Problem A. Hi Young Guangzhou Input file: Output file: Time limit: Memory limit: standard input standard output 2 seconds 1024 megabytes

Guangzhou, also known as Canton and the "City of Rams", is a vibrant metropolis with over 2,200 years of history. As a vital starting point of the ancient Maritime Silk Road, it has been a major port for international trade since the Qin and Han dynasties. In the year just passed, the 15th National Games concluded successfully in Guangzhou. The spirit of hard work of the athletes still thrives in this city.

Picture 1: "Dawanji" at Guangzhou Baiyun International Airport

Now, you and your teammate are making a plan to travel around Guangzhou. There are $n$ tourist attractions you want to visit. Also, you plan to stay in Guangzhou for $m$ days. There are $n-1$ relationships among the attractions. Each relationship connects two attractions, indicating that they are closely related in history or scenery. Additionally, any two different attractions can reach each other through one or more relationships, meaning that the relationships form a tree. You decide to visit each attraction exactly once. Let $b_i$ be the day on which the $i$-th attraction is visited. Your plan should satisfy: The hotel you booked on the $i$-th day is near the attraction $a_i$. That means you should visit the attraction $a_i$ on the day $i$. In other words, $b_{a_i} = i$ for every $i = 1, 2, \dots, m$. For each attraction $i$ ($1 \le i \le n$), the number of relationships connecting it to other attractions that are visited on the same day (the $b_i$-th day) is no less than the number of such relationships for any other day. In other words, for every $u = 1, 2, \dots, n$ and every $t = 1, 2, \dots, m$, the following must hold $\sum_{(u,v) \in E} [b_v = b_u] \ge \sum_{(u,v) \in E} [b_u = t]$, where $E$ is the set of all relationships.

So, now make your plan! Construct any possible $b_1, b_2, \dots, b_n$ satisfying the above conditions, or show that it is impossible to do so.

输入格式

Each test contains multiple test cases. The first line contains one integer $t$ ($1 \le t \le 10^5$), indicating the number of test cases. The description of the test cases follows.

The first line contains two integers $n, m$ ($1 \le m \le n \le 10^5$, $1 < \sum n, \sum m \le 10^6$), indicating the number of attractions and the number of days you will stay. The second line contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le n$, $a_i \ne a_j$ for $1 < i < j < m$), indicating you must visit attraction $a_i$ on the day $i$. The next $n-1$ lines, each line contains two integers $u_i, v_i$ ($1 \le u_i, v_i \le n$), indicating a relationship.

输出格式

For each test case, if you can't make a valid plan, output NO. Otherwise, output two lines. The first line contains one word YES, and the second line contains $b_1, b_2, \dots, b_n$ ($1 \le b_i \le m$) indicating your plan. If there are multiple valid answer, you may output any of them.

样例

输入 1

4
1 1
1
4 2
2 3
1 2
2 3
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

说明

Picture 2: Example figure for Test case 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.