QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#9996. 辞甲猾扎

統計

题目描述

给你一棵 $n$ 个点的无根树,有 $k$ 个点初始为黑色,其余点初始为灰色,你可以在一开始将一些灰色点染成白色。染完后,现在进行如下操作,直到树上不存在灰色点。

每一轮对所有灰色点同时进行如下操作:

  1. 检查与该灰色点 $u$ 直接相连的点有没有黑色或白色点,如果没有,则 $u$ 保持灰色。
  2. 如果与 $u$ 直接相连的点有白色点,则 $u$ 变为白色。
  3. 如果与 $u$ 直接相连的点有黑色点,则 $u$ 变为黑色。

这个顺序说明同时与白色和黑色相邻时会被染成白色。

注意此处对所有灰色点同时进行操作,也就是说在这一轮被染上颜色的点不能作为其它点改变颜色的根据。

现在求一开始最少染几个点为白色,可以使树最终黑色点不超过 $k$ 个。

输入格式

从标准输入读入数据。

第一行两个整数 $n,k\;(1\le n\le 10^6,1\le k \le n)$,含义见上文。

第二行 $k$ 个整数,代表一开始被染成黑色的点的标号。

第 $3\sim n+2$ 行每行两个整数 $u,v\;(1\le u,v\le n)$,代表一条树上的边。

输出格式

输出到标准输出。

一行一个整数,为答案。

样例

输入

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

输出

1

样例二

见下载目录下的 ex_2.inex_2.ans

解释

  • 对于第一组样例,一开始将 $2$ 号点染白即可
  • 对于第二组样例,一开始将 $3,,4,9$ 号点染白为满足条件且数量最小一组方案
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.