易错点:
- 将边权转化为0/1判定性问题.
#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
const int MAXN=1000010,MAXM=1000010,INF=2100000000;
int n;
struct Edge{
int from,to,w,nxt;
}e[MAXM];
int head[MAXN],edgeCnt=0;
void addEdge(int u,int v,int w){
e[++edgeCnt].from=u;
e[edgeCnt].to=v;
e[edgeCnt].w=w;
e[edgeCnt].nxt=head[u];
head[u]=edgeCnt;
}
int dis[MAXN],s;
struct Node{
int nowPoint,nowValue;
bool operator <(const Node &a)const{
return a.nowValue<nowValue;
}
};
int nowK=-1;//现在二分的值
int dijkstra(){
priority_queue<Node> q;
for(int i=1;i<=n;i++){
dis[i]=INF;
}
q.push(Node{s,0});dis[s]=0;
while(!q.empty()){
Node nowNode=q.top();q.pop();
int nowPoint=nowNode.nowPoint,nowValue=nowNode.nowValue;
if(dis[nowPoint]!=nowValue)continue;
for(int i=head[nowPoint];i;i=e[i].nxt){
int nowV=e[i].to;
int tmpW=e[i].w>nowK?1:0;
if(dis[nowV]>dis[nowPoint]+tmpW){
dis[nowV]=dis[nowPoint]+tmpW;
q.push(Node{nowV,dis[nowPoint]+tmpW});
}
}
}
return dis[n];
}
const int MAXL=1000005;
int main(){
int m,k;//边数和免费量
scanf("%d%d%d",&n,&m,&k);
s=1;
for(int i=1;i<=m;i++){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
addEdge(u,v,w);
addEdge(v,u,w);
}
dijkstra();
int l=0,r=MAXL;
int ans=2000000001;
while(l<r){
int mid=(l+r)>>1;
nowK=mid;
if(dijkstra()>k)l=mid+1;
else r=mid;
}
if(l==MAXL){
printf("-1\n");
}else printf("%d\n",r);
return 0;
}