Nelson @ 2019-09-29 20:56:40
#include<bits/stdc++.h>
using namespace std;
int read(){
int x=0,f=1;
char c=getchar();
while(!isdigit(c)){
if(c=='-') f=-1;
c=getchar();
}
while(isdigit(c)){
x=(x<<1)+(x<<3)+(c^48);
c=getchar();
}
return x*f;
}
const int N=5e4+10;
const int inf=1e9+10;
int n,m,b,mid,maxcost,ans,cnt;
int fa[N],cost[N],judge[N],head[N<<1],dis[N];
struct edge{
int to,next,w;
}e[N<<1];
struct node{
int pos,len;
bool operator<(const node &x)const{
return x.len<len;
}
};
priority_queue<node> q;
void addedge(int from,int to,int w){
e[++cnt]=(edge){to,head[from],w};
head[from]=cnt;
}
int find(int x){
return fa[x]==x?x:fa[x]=find(fa[x]);
}
void dij(){
maxcost=cost[1];
dis[1]=0;
q.push((node){1,0});
while(!q.empty()){
int u=q.top().pos;
q.pop();
if(judge[u]) continue;
judge[u]=1;
for(int i=head[u];i;i=e[i].next){
int v=e[i].to,w=e[i].w,l=cost[v];
if(l>mid) continue;
maxcost=max(maxcost,l);
if(dis[v]>dis[u]+w){
dis[v]=dis[u]+w;
if(!judge[v]){
q.push((node){v,w});
}
}
}
}
}
int main(){
n=read();m=read();b=read();
ans=inf;
for(int i=1;i<=n;i++){
fa[i]=i;
cost[i]=read();
}
for(int i=1,x,y,z;i<=m;i++){
x=read();y=read();z=read();
addedge(x,y,z);
addedge(y,x,z);
fa[find(x)]=find(y);
}
if(fa[find(1)]!=fa[find(n)]){
printf("AFK");
return 0;
}
int l=0,r=inf;
while(l<=r){
mid=(l+r)>>1;
maxcost=0;
for(int i=1;i<=n;i++){
dis[i]=inf;
judge[i]=0;
}
dij();
if(dis[n]>b){
l=mid+1;
}
else{
r=mid-1;
ans=min(ans,maxcost);
}
}
printf("%d",ans);
return 0;
}
我的思路大概就是二分+dijkstra,但是不知道咋有三个点炸了。 https://www.luogu.org/problem/P1462
by 黯黑の夜 @ 2019-09-29 20:58:23
这是刚学会开电脑的人吗
by jxyzs @ 2019-09-29 20:59:13
萌新刚学会买电脑,求教
by Nikolai_Krukov @ 2019-09-29 20:59:30
%%%%%%%%%tql
by Nelson @ 2019-09-29 21:00:02
@weng200744 qwq因为太菜了,现在还不会关机哦
by exit0 @ 2019-09-29 21:02:48
%%%%%%%%%tql
by XyzLde小号 @ 2019-09-29 21:03:07
萌新刚学会买电脑,求教,怎么开机,找不到按钮
@Nelson
by Nelson @ 2019-09-29 21:04:41
@王治理de小号 兄dei你这有点过分了hhhh
by 辰星凌 @ 2019-09-29 21:05:50
long long?
by 辰星凌 @ 2019-09-29 21:06:25
我开int只有82分
by _maze @ 2019-09-29 21:07:52
@萌新南凉北暖 电脑没有显示器,你要雇用大约一万个勤快的小精灵用来举显示牌......