QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 512 MB 總分: 110

#12049. 旅行

统计

Malnar 先生终于迎来了他的年度假期。他决定前往的国家可以表示为 $n$ 个城市和连接它们的 $m$ 条双向道路。每条道路的长度相同,且通过这些道路可以从任意城市到达其他任何城市。从城市 $a$ 到城市 $b$ 的路径定义为一条道路序列,使得从城市 $a$ 出发,依次经过该序列中的道路,最终到达城市 $b$。路径的长度定义为该路径上道路的数量。

Malnar 先生习惯性地预订了其中一个城市最昂贵的酒店,然后开始规划他的旅程。为了方便规划,他记录了从酒店到每个城市所需的最短路径长度。

由于对期待已久的假期感到兴奋,Malnar 先生完全忘记了酒店位于哪个城市。他当然不想错过这次旅行,所以他请求你确定酒店可能位于哪些城市。

输入格式

第一行包含自然数 $n$ 和 $m$ —— 城市数量和连接它们的道路数量 ($1 \le n \le 5 \cdot 10^4$, $n - 1 \le m \le 10^5$)。

接下来的 $m$ 行,第 $i$ 行包含数字 $u_i$ 和 $v_i$ —— 表示城市 $u_i$ 和 $v_i$ 之间有一条道路 ($1 \le u_i, v_i \le n$, $u_i \neq v_i$)。任意两个城市之间最多只有一条道路。

最后一行包含 $n$ 个整数 —— 第 $i$ 个数字 $d_i$ 表示从第 $i$ 个城市到酒店所在城市的距离,如果 Malnar 先生没有记录该距离,则为 $-1$ ($-1 \le d_i < n$)。

输出格式

第一行输出酒店可能位于的城市数量。

第二行按升序输出酒店可能位于的城市编号。

子任务

子任务 分值 约束
1 10 $m + 1 = n \le 5000$, $u_i + 1 = v_i$ 对所有 $i$ 成立
2 20 $d_i = -1$ 对所有 $i > 1$ 成立
3 35 $n, m \le 5000$
4 45 无附加约束

样例

输入格式 1

7 6
1 2
1 3
3 4
3 5
3 6
5 7
2 -1 -1 -1 -1 -1 3

输出格式 1

2
4 6

说明

从编号为 4 的城市到编号为 1 的城市的路径长度为 2,而从编号为 4 的城市到编号为 7 的城市的路径长度为 3。因此,城市 4 满足这两个条件,酒店可能位于该城市。 编号为 6 的城市情况相同。

输入格式 2

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

输出格式 2

2
3 5

输入格式 3

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

输出格式 3

0

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.