CF1307D.Cow and Fields

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Bessie is out grazing on the farm, which consists of nn fields connected by mm bidirectional roads. She is currently at field 11 , and will return to her home at field nn at the end of the day.

The Cowfederation of Barns has ordered Farmer John to install one extra bidirectional road. The farm has kk special fields and he has decided to install the road between two different special fields. He may add the road between two special fields that already had a road directly connecting them.

After the road is added, Bessie will return home on the shortest path from field 11 to field nn . Since Bessie needs more exercise, Farmer John must maximize the length of this shortest path. Help him!

输入格式

The first line contains integers nn , mm , and kk ( 2n21052 \le n \le 2 \cdot 10^5 , n1m2105n-1 \le m \le 2 \cdot 10^5 , 2kn2 \le k \le n ) — the number of fields on the farm, the number of roads, and the number of special fields.

The second line contains kk integers a1,a2,,aka_1, a_2, \ldots, a_k ( 1ain1 \le a_i \le n ) — the special fields. All aia_i are distinct.

The ii -th of the following mm lines contains integers xix_i and yiy_i ( 1xi,yin1 \le x_i, y_i \le n , xiyix_i \ne y_i ), representing a bidirectional road between fields xix_i and yiy_i .

It is guaranteed that one can reach any field from every other field. It is also guaranteed that for any pair of fields there is at most one road connecting them.

输出格式

Output one integer, the maximum possible length of the shortest path from field 11 to nn after Farmer John installs one road optimally.

输入输出样例

  • 输入#1

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

    输出#1

    3
  • 输入#2

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

    输出#2

    3

说明/提示

The graph for the first example is shown below. The special fields are denoted by red. It is optimal for Farmer John to add a road between fields 33 and 55 , and the resulting shortest path from 11 to 55 is length 33 .

The graph for the second example is shown below. Farmer John must add a road between fields 22 and 44 , and the resulting shortest path from 11 to 55 is length 33 .

首页