求助,72,WA6,8,11

P1462 通往奥格瑞玛的道路

DuskLight @ 2021-08-25 17:30:02

#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cstdio>
#include<bits/stdc++.h>
#define ll long long 
#define f(a,b,c) for(int a=b;a<=c;a++)
using namespace std;
ll fread(){
    ll x=0,s=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')s=-1;
        ch=getchar();
    }
    while(ch<='9'&&ch>='0'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return s==1?x:-x;
}
struct node {
    ll v;
    ll val;
    node (ll a , ll b){
        v=a,val=b;
    }
    bool operator < (const node &x) const{
                x.val<val;
    }

};
priority_queue<node> q;
vector<node> edge[50005];
ll n,m,b;
ll f[10005];
bool vis[50005];
int dis[50005];
int ans=0x3f3f3f3f;
bool dijs(ll mid){
    fill (dis+2,dis+1+n,0x3f3f3f3f) ;
    memset(vis,0,sizeof(vis));
    q.push(node(1,0));
    while(!q.empty()){
        node temp=q.top();
        q.pop();
        ll uu=temp.v;
        if(vis[uu]) continue;
        vis[uu]++;
        for(int i=0;i<edge[uu].size();i++){
            ll vv=edge[uu][i].v;
            ll ww=edge[uu][i].val;
            if(f[vv]>mid) continue;
            if(dis[vv]>dis[uu]+ww){
                dis[vv]=dis[uu]+ww;
                q.push(node(vv,dis[vv]));
            } 
        }
    }
    return dis[n]<b;   //如果血没了返回假,能走到就返回真 
}

int main(){
    n=fread();
    m=fread();
    b=fread(); 
    f(i,1,n){
        f[i]=fread();
    }
    f(i,1,m){
        ll u=fread();
        ll v=fread();
        ll w=fread();
        if(u==v)continue;
        edge[u].push_back(node(v,w));
        edge[v].push_back(node(u,w));
    }
    dis[1]=0;
    ll l=1,r=1000000000;
    if(!dijs(r)){
        printf("AFK");
        return 0;
    }
    while(l<=r){
        ll mid=(l+r)>>1;
        if(dijs(mid)){ ;             // 如果能走到,是真,说明钱数可以降低(减少走的点) 
        r=mid-1; 
        }
        else{
            l=mid+1;
        } 
    }     

    printf("%d",l);
    return 0;

} 

|