CF1307D.Cow and Fields
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Bessie is out grazing on the farm, which consists of n fields connected by m bidirectional roads. She is currently at field 1, and will return to her home at field n at the end of the day.
The Cowfederation of Barns has ordered Farmer John to install one extra bidirectional road. The farm has k 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 1 to field n. Since Bessie needs more exercise, Farmer John must maximize the length of this shortest path. Help him!
贝茜正在农场上吃草。农场由 n 块田地和 m 条双向道路组成。她当前位于第 1 块田地,一天结束时将返回位于第 n 块田地的家。
“牛联邦”(Cowfederation of Barns)已命令农夫约翰额外修建一条双向道路。农场中有 k 块特殊田地,他决定将这条新道路建在这 k 块特殊田地中的两个不同田地之间。他可以在两个已经直接由一条道路相连的特殊田地之间再修建一条道路。
新增道路后,贝茜将沿着从第 1 块田地到第 n 块田地的最短路径回家。由于贝茜需要更多锻炼,农夫约翰必须使该最短路径的长度最大化。请帮助他!
输入格式
The first line contains integers n, m, and k (2≤n≤2⋅105, n−1≤m≤2⋅105, 2≤k≤n) — the number of fields on the farm, the number of roads, and the number of special fields.
The second line contains k integers a1,a2,…,ak (1≤ai≤n) — the special fields. All ai are distinct.
The i-th of the following m lines contains integers xi and yi (1≤xi,yi≤n, xi=yi), representing a bidirectional road between fields xi and yi.
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.
第一行包含三个整数 n、m 和 k(2≤n≤2⋅105,n−1≤m≤2⋅105,2≤k≤n)——分别表示农场上的田地数量、道路数量以及特殊田地数量。
第二行包含 k 个整数 a1,a2,…,ak(1≤ai≤n)——表示特殊田地。所有 ai 互不相同。
接下来的 m 行中,第 i 行包含两个整数 xi 和 yi(1≤xi,yi≤n,xi=yi),表示田地 xi 与田地 yi 之间有一条双向道路。
保证任意两块田地之间均可相互到达。同时保证任意两块田地之间至多只有一条道路相连。
输出格式
Output one integer, the maximum possible length of the shortest path from field 1 to n after Farmer John installs one road optimally.
输出一个整数,表示约翰先生最优地修建一条道路后,从牧场 1 到牧场 n 的最短路径的最大可能长度。
输入输出样例
输入#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 3 and 5, and the resulting shortest path from 1 to 5 is length 3.

The graph for the second example is shown below. Farmer John must add a road between fields 2 and 4, and the resulting shortest path from 1 to 5 is length 3.

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

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

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