QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 256 MB 總分: 100

#2660. Agenci

统计

在 Bajtocja 有 $k$ 名特工。他们必须访问该国的所有 $n$ 个城市,但为了不引起反间谍机构的怀疑:

  • 每天恰好有一名特工可以从他所在的城市移动到与之相邻的城市;
  • 每个城市只能由一名特工访问(但可以被多次经过)。

Bajtocja 的道路网非常精简,由 $n-1$ 条道路组成。从任何一个城市都可以到达其他任何城市,可能需要经过其他城市。

请编写一个程序,计算特工访问该国所有城市所需的最少天数。我们假设特工出发的城市已经被访问过。

输入格式

输入的第一行包含两个整数 $n$ 和 $k$ ($2 \le n \le 500\,000, 1 \le k \le n$),分别表示 Bajtocja 的城市数量和特工数量。城市编号为 $1$ 到 $n$。

第二行包含一个递增的 $k$ 个整数序列,取值范围在 $[1, n]$,表示特工的初始位置城市编号。

接下来的 $n-1$ 行描述了 Bajtocja 的道路网。每行包含一对整数 $a, b$ ($1 \le a, b \le n, a \neq b$),表示城市 $a$ 和 $b$ 之间存在一条道路。

输出格式

你的程序应输出一行,包含一个整数,表示特工访问所有 Bajtocja 城市所需的最少天数。

样例

样例输入 1

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

样例输出 1

5

说明 1

第一个特工可以访问城市 $2 \to 1 \to 2 \to 3$,这需要 $3$ 天;第二个特工访问城市 $6 \to 5 \to 4$,这需要 $2$ 天。

子任务

子任务 附加条件 分值
1 $n \le 10$ 6
2 $n \le 20$ 13
3 $n \le 2000$ 27
4 $k = 1$ 10
5 $k = 2$ 7
6 每个城市最多与两个其他城市相邻 7
7 无附加条件 30

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.