QOJ.ac

QOJ

Time Limit: 4 s Memory Limit: 1024 MB Total points: 100

#5580. 分支经理

Statistics

你正在管理一个城市间的单向道路交通网络。人们依次从同一个城市出发,穿过交通网络,每个人都会等待前一个人停止移动后再开始。在到达目的地之前,人们遵循一个简单的算法:他们会查看当前城市的所有出路,并选择通往编号最小的城市的道路。当一个人到达目的地,或者到达一个没有出路的城市时,他就会停止移动。如果任何人在任何时候未能到达目的地,那么排在后面等待的所有人都会离开。

在每个人进入交通网络之前,你可以永久关闭任意数量的道路,以确保他们能到达目的地。你选择关闭的道路将不再对后续的人开放。

共有 $n$ 个城市,编号从 $1$ 到 $n$。共有 $n-1$ 条有向道路,每条道路总是从编号较小的城市指向编号较大的城市。该网络形成一棵以城市 $1$ 为根的树。有 $m$ 个人想要穿过这个网络。每个人都从城市 $1$ 出发,并有一个特定的目标城市 $d$。这些人将按给定的顺序排队。如果你能最优地关闭道路,你能引导多少人正确到达他们的目的地?

输入格式

第一行包含两个整数 $n$ 和 $m$ ($2 \le n, m \le 2 \times 10^5$),其中 $n$ 是城市数量,$m$ 是人数。

接下来的 $n-1$ 行,每行包含两个整数 $a$ 和 $b$ ($1 \le a < b \le n$),表示一条从城市 $a$ 到 $b$ 的有向道路。这些道路描述了一棵以城市 $1$ 为根的树。

接下来的 $m$ 行,每行包含一个整数 $d$ ($2 \le d \le n$),表示队列中下一个人想要到达的目标城市。

输出格式

输出一个整数,表示你能引导至正确目的地的最大人数。

样例

样例输入 1

8 5
1 2
4 8
4 6
1 4
2 5
4 7
2 3
5
2
6
4
8

样例输出 1

5

样例输入 2

4 4
1 2
1 3
1 4
3
2
3
4

样例输出 2

1

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.