Name1 @ 2022-04-05 21:21:39
#include<iostream>
#include<cstring>
#include<queue>
#define MAXN 1000000005
using namespace std;
const int N=5e4+10;
const int inf=2e9+10;
//
struct Edge{
int next,to,c;
}g[N];
int cnt,head[N];
void add(int x,int y,int c)
{
g[++cnt]=(Edge){head[x],y,c};
head[x]=cnt;
}
//
struct node{
int x,dis;node(int x=0,int dis=0):x(x),dis(dis){};
bool operator <(const node &a) const{return a.dis<dis;}
};
int n,m,b,f[N],dis[N],vis[N];
bool dijkstra(int po)
{
priority_queue<node>q;
memset(dis,inf,sizeof(dis));
memset(vis,0,sizeof(vis));
q.push(node(1,0)),dis[1]=0;
while(!q.empty())
{
int u=q.top().x;q.pop();if(vis[u]) continue;vis[u]=1;
for(int i=head[u];i;i=g[i].next)
{
int x=g[i].to,c=g[i].c;
if(f[x]<=po&&dis[u]+c<dis[x])
{
dis[x]=dis[u]+c;
q.push(node(x,dis[x]));
}
}
}
if(dis[n]<b) return true;
else return false;
}
int main()
{
cin>>n>>m>>b;
for(int i=1;i<=n;i++)
cin>>f[i];
while(m--)
{
int x,y,c;
cin>>x>>y>>c;
add(x,y,c);
add(y,x,c);
}
if(!dijkstra(MAXN)){
cout<<"AFK";return 0;
}
int l=1,r=MAXN;
while(l<=r)
{
int mid=(l+r)>>1;
if(dijkstra(mid)) r=mid-1;
else l=mid+1;
}
cout<<l;
return 0;
}
不仅超了时,还给我整错了几个,求大佬帮忙看看哪出了问题
by Cerisier @ 2022-04-05 21:38:29
现在你是 100 unaccept 吧?
by Cerisier @ 2022-04-05 21:38:49
起点花费也要计入其中