GameFreak @ 2022-08-19 20:59:40
哪个大佬帮我看看,我开了long long还是过不了。。。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>
inline T Min(T x,T y){
return x<y?x:y;
}
template<class T>
inline T Max(T x,T y){
return y<x?x:y;
}
inline ll read(){
ll x=0;char ch=getchar();
while('0'>ch||'9'<ch)ch=getchar();
while('0'<=ch&&'9'>=ch)x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x;
}
const ll MAXN=10005;
ll n=read(),m=read(),b=read();
ll f[MAXN];
struct Node{
ll to;
ll w;
};
bool operator<(Node x,Node y){
return x.w>y.w;
}
vector<Node> G[MAXN];
ll dis[MAXN];
bool vis[MAXN];
inline bool check(ll x){
if(f[1]>x) return 0;
priority_queue<Node> Q;
for(ll i=1;i<=n;i++) dis[i]=0x7ffffffffffffff,vis[i]=0;
dis[1]=0;
Q.push({1,0});
while(!Q.empty()){
ll now=Q.top().to;
Q.pop();
if(vis[now]) continue;
vis[now]=1;
for(Node p:G[now]){
ll v=p.to,w=p.w;
if(f[v]>x) continue;
if(dis[v]>dis[now]+w){
dis[v]=dis[now]+w;
if(v==n) return dis[v]<=b;
Q.push({v,dis[v]});
}
}
}
return 0;
}
signed main(){
ll L=0x7ffffffffffffff,R=-L;
for(ll i=1;i<=n;i++){
f[i]=read();
R=Max(R,f[i]),L=Min(L,f[i]);
}
for(ll i=1;i<=m;i++){
ll u=read(),v=read(),w=read();
G[u].push_back({v,w}),G[v].push_back({u,w});
}
ll l=L-1,r=R+1;
while(l<r){
ll mid=(l+r)>>1ll;
if(check(mid)) r=mid;
else l=mid+1;
}
if(l==R+1) printf("AFK");
printf("%lld",l);
return 0;
}
by GameFreak @ 2022-08-19 21:10:51
抱歉,本人脑子抽风了,if
语句没打完。。。(我说怎么告诉我答案太长了。。。)