QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 2048 MB مجموع النقاط: 100

#2524. 甜点咖啡馆

الإحصائيات

Kim 想要创业,他大学毕业后一直准备开一家甜点咖啡馆。Kim 所居住城镇的道路网络构成了一棵树,即一个连通的无环图,如下图所示。城镇中有 $n$ 个甜点咖啡馆的候选地址。在下图中,圆圈代表候选地址,连接两个候选地址的线段代表道路,线段上标注的数值代表道路的长度。

城镇中有 $k$ 个公寓区,因此他希望自己的甜点咖啡馆尽可能靠近某个公寓区。在上图中,有三个公寓区分别位于标记为 A、B 和 C 的候选地址。考虑到竞争力和盈利能力,他认为满足以下条件的候选地址是一个“好地方”。

令 $d(x, y)$ 为道路网络中两个候选地址 $x$ 和 $y$ 之间的最短路径长度。如果存在一个设有公寓区的候选地址 $z$,使得对于每个候选地址 $q$ ($q \neq p$),都有 $d(p, z) < d(q, z)$,则称候选地址 $p$ 是一个“好地方”。

在上图中,候选地址 2、4、5、6、8 和 9 是好地方。更具体地说,例如,候选地址 6 是一个好地方,因为它比除候选地址 5 之外的任何其他候选地址都更靠近公寓区 B,并且比候选地址 5 更靠近公寓区 A。也就是说,在候选地址 5 处存在公寓区 B,满足对于所有 $q \in \{1, 2, 3, 4, 7, 8, 9\}$,都有 $d(6, 5) < d(q, 5)$;同时在候选地址 2 处存在公寓区 A,满足 $d(6, 2) < d(5, 2)$。候选地址 7 不是一个好地方,因为没有任何公寓区比候选地址 6 更靠近它。

给定城镇中候选地址和公寓区的信息,编写一个程序来输出好地方的数量。

输入格式

程序从标准输入读取数据。输入的第一行包含两个整数 $n$ 和 $k$ ($3 \le n \le 100,000$, $1 \le k \le n$),其中 $n$ 是候选地址的数量,$k$ 是公寓区的数量。候选地址编号从 1 到 $n$。接下来的 $n-1$ 行,每行包含三个整数 $i, j$ 和 $w$ ($1 \le i, j \le n$, $1 \le w \le 1,000$),表示候选地址 $i$ 和 $j$ 之间存在一条长度为 $w$ 的道路。最后一行包含 $k$ 个整数,表示城镇中公寓区所在的地址。

输出格式

程序将结果写入标准输出。仅输出一行,包含好地方的数量。

样例

样例输入 1

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

样例输出 1

6

样例输入 2

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

样例输出 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.