题意:

给n,m,k,有n个点,m条线,距离都是一;

有k个特殊点,选择其中两个,进行相连,距离变为1,使得原本的最短路,经过相连改变小或者不变,最终结果是所有结果里面的最大距离。

思路:

选择i,j两个点(满足从1出发先遇到 i ,在遇到 j ),1~i+j~n+1就是新的最短路(1~i表示 1 到 i 最短距离,j~n表示 j 到 n 最短距离)

所以只要算出1到所有点的最短距离dis[0][N] 和 n到所有点的最短距离dis[1][N],再选择特殊点进行相连,因为最大化的话,肯定是要选择两个特殊点靠得近的排序

同时,满足特殊点按照从1出发先遇到的顺序来,因为可能是先遇到 j 点,导致 会有1~i+j~n+1>1~j+i~n+1的情况

比较就用1~i+j~n<1~j+i~n,然后操作有点像尺缩,叙述能力有限

最后还要进行与1~n进行比较大小,这个用图解释比较直观

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define it register int
#define inf 0x3f3f3f3f
#define lowbit(x) (x)&(-x)
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 998244353
const int N=2e5+;
struct node{
int v,next;
}d[N<<];
struct node1{
int x,bu;
node1(){}
node1(int xx,int buu):x(xx),bu(buu){}
friend bool operator<(const node1 a,const node1 b){
if(a.bu==b.bu){
return a.x>b.x;
}
return a.bu>b.bu;
}
};
int n,m,k;
int a[N],head[N],tot;
int dis[][N];
il void add(int u,int v){
d[tot].v=v;d[tot].next=head[u];
head[u]=tot++;
}
void bfs(int x,int c){
dis[c][x]=;
priority_queue<node1>q;
q.push(node1(x,));
while(!q.empty()){
node1 t=q.top();q.pop();
int u=t.x,bu=t.bu;
for(it i=head[u];~i;i=d[i].next){
int v=d[i].v;
if(dis[c][v]==-){
dis[c][v]=bu+;
q.push(node1(v,bu+));
}
}
}
}
bool cmp(int x,int y){
return dis[][x]+dis[][y]<dis[][y]+dis[][x];
}
int main(){
tot=;
scanf("%d%d%d",&n,&m,&k);
for(it i=;i<=n;i++){head[i]=-,dis[][i]=dis[][i]=-;}
for(it i=;i<k;i++){
scanf("%d",&a[i]);
}
for(it i=;i<m;i++){
int u,v;scanf("%d%d",&u,&v);
add(u,v),add(v,u);
}
bfs(,);bfs(n,);
sort(a,a+k,cmp);
int ans=dis[][a[]],da=-;
for(it i=;i<k;i++){
da=max(da,ans+dis[][a[i]]+);
ans=max(ans,dis[][a[i]]);
}
printf("%d\n",min(dis[][n],da));
return ;
}
/*
5 5 2
2 4
1 5
4 5
3 4
2 3
1 2
*/

Codeforces Round #621 (Div. 1 + Div. 2) D的更多相关文章

  1. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  2. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  3. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  4. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  5. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  6. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  7. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  8. Educational Codeforces Round 39 (Rated for Div. 2) G

    Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...

  9. Educational Codeforces Round 48 (Rated for Div. 2) CD题解

    Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...

  10. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

随机推荐

  1. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

  2. mysql中获取本月第一天、本月最后一天、上月第一天、上月最后一天等等

    转自: https://blog.csdn.net/min996358312/article/details/61420462 1.当函数使用时,即interval(),为比较函数,如:interva ...

  3. 如何通过给MM修电脑培养感情

    文章来自网络 在修之前,向MM反复声明,这电脑故障是有硬件和软件之分的,如果是硬件故障,例如显卡风扇不转了,显示器连线老化,显示器分辨率超出显示器指标,等等都会导致黑屏啊,这个我不回家用专门的工具是修 ...

  4. ActiveMQ使用JDBC持久化

    步骤一:创建一个数据库            步骤二:配置activemq.xml配置文件                1.在persistenceAdapter加入如下配置 <!--crea ...

  5. url 获取 geoserver 中对应的style

    http://userName:password@127.0.0.1:7093/geoserver/rest/workspaces/FAST/styles/AVG_RSRP.sld

  6. mycat linux上目录介绍

    1.本文引用来自mycat官方文档,具体可以浏览mycat官网 2.linux系统下面的目录 MyCAT 有提供编译好的安装包,支持 windows.Linux.Mac.Solaris 等系统上安装与 ...

  7. cursor 把鼠标指针的形状弄成一只伸出食指的手

    <span style="cursor:auto">auto</span><br> <span style="cursor:cr ...

  8. Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type

    问题描述 将项目挂载到 Myeclipse 的 tomcat 上,启动 tomcat ,报错“Initialization of bean failed; nested exception is ja ...

  9. linux异常

    常见报错语句 Command not found; - 找不到命令(敲入的命令有误或者该命令还没安装) No Such file or directory; - 找不到输入的文件或者目录

  10. TD - 数据验证

    基本方法 this.assetCounts.focus();//聚焦 this.btnSave.cancel();//按钮取消 this.assetPerson.isValid()//是否有效,tru ...