CF1307D.Cow and Fields

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

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!

贝茜正在农场上吃草。农场由 nn 块田地和 mm 条双向道路组成。她当前位于第 11 块田地,一天结束时将返回位于第 nn 块田地的家。

“牛联邦”(Cowfederation of Barns)已命令农夫约翰额外修建一条双向道路。农场中有 kk 块特殊田地,他决定将这条新道路建在这 kk 块特殊田地中的两个不同田地之间。他可以在两个已经直接由一条道路相连的特殊田地之间再修建一条道路。

新增道路后,贝茜将沿着从第 11 块田地到第 nn 块田地的最短路径回家。由于贝茜需要更多锻炼,农夫约翰必须使该最短路径的长度最大化。请帮助他!

输入格式

The first line contains integers nn, mm, and kk (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5, n−1≤m≤2⋅105n-1 \le m \le 2 \cdot 10^5, 2≤k≤n2 \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 (1≤ai≤n1 \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 (1≤xi,yi≤n1 \le x_i, y_i \le n, xi≠yix_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.

第一行包含三个整数 nn、mm 和 kk(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5,n−1≤m≤2⋅105n-1 \le m \le 2 \cdot 10^5,2≤k≤n2 \le k \le n)——分别表示农场上的田地数量、道路数量以及特殊田地数量。

第二行包含 kk 个整数 a1,a2,…,aka_1, a_2, \ldots, a_k(1≤ai≤n1 \le a_i \le n)——表示特殊田地。所有 aia_i 互不相同。

接下来的 mm 行中,第 ii 行包含两个整数 xix_i 和 yiy_i(1≤xi,yi≤n1 \le x_i, y_i \le n,xi≠yix_i \ne y_i),表示田地 xix_i 与田地 yiy_i 之间有一条双向道路。

保证任意两块田地之间均可相互到达。同时保证任意两块田地之间至多只有一条道路相连。

输出格式

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

输出一个整数,表示约翰先生最优地修建一条道路后,从牧场 11 到牧场 nn 的最短路径的最大可能长度。

输入输出样例

  • 输入#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.

第一个示例的图如下所示。特殊地块用红色标出。对约翰农夫而言,最优方案是在地块 33 和 55 之间修建一条道路,此时从地块 11 到地块 55 的最短路径长度为 33。

第二个示例的图如下所示。约翰农夫必须在地块 22 和 44 之间修建一条道路,此时从地块 11 到地块 55 的最短路径长度为 33。

输入解题思路,AI测评打分。不知道怎么写?

首页