题目描述
Problem Description
Mr. Malnar has finally taken his annual leave. The country he plans to visit can be represented by $n$ cities and $m$ bidirectional roads connecting them. Each road has the same length, and it is possible to travel from any city to any other city using these roads. The path from city $a$ to city $b$ is defined as a sequence of roads such that starting from city $a$, one traverses the roads in the sequence and eventually reaches city $b$. The length of the path is defined as the number of roads in this path.
As usual, Mr. Malnar booked the most expensive hotel in one of the cities and started planning his journey. For convenience, he recorded the shortest path lengths from the hotel to each city.
Excited about his long-awaited vacation, Mr. Malnar completely forgot which city the hotel was in. He certainly doesn't want to miss this trip, so he asks you to determine which cities the hotel could possibly be in.
Input Format
The first line contains two integers $n$ and $m\ (1\le n\le 5\cdot 10^4, n-1\le m\le 10^5)$, representing the number of cities and roads, respectively.
The next $m$ lines each contain two integers $u_i, v_i\ (1\le u_i, v_i\le n, u_i\neq v_i)$, indicating that there is a road between city $u_i$ and city $v_i$. No two cities are connected by more than one road.
The last line contains $n$ integers, where the $i$-th integer $d_i\ (-1\le d_i<n)$ represents the path length from city $i$ to the hotel's city. If Mr. Malnar did not record this value, it is denoted as $-1$.
Output Format
The first line should output the number of cities where the hotel could be located.
The second line should output the city numbers where the hotel could be located, in ascending order.
Sample Input and Output
Sample Input #1
7 6
1 2
1 3
3 4
3 5
3 6
5 7
2 -1 -1 -1 -1 -1 3
Sample Output #1
2
4 6
Sample Input #2
6 6
1 2
2 3
3 4
4 5
5 6
6 1
2 -1 -1 1 -1 -1
Sample Output #2
2
3 5
Sample Input #3
4 3
1 2
2 3
3 4
1 -1 -1 1
Sample Output #3
0
Notes/Hints
Sample Explanation 1
The path length from city $4$ to city $1$ is $2$, and from city $4$ to city $7$ is $3$. Therefore, city $4$ meets both conditions, and the hotel could be there.
The same situation applies to city $6$.
Subtasks
| Subtask Number | Additional Constraints | Score |
|---|---|---|
| $1$ | $m+1=n\le 5\ 000$, for all $i$ where $u_i+1=v_i$ | $10$ |
| $2$ | For all $i>1$, $d_i=-1$ | $20$ |
| $3$ | $n, m\le 5\ 000$ | $35$ |
| $4$ | No additional constraints | $45$ |
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分