WA后两个点,求调

P1462 通往奥格瑞玛的道路

lihaoyyy @ 2024-07-31 15:53:12

WA后两点:

#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int I=0x3f3f3f3f;
int n,m,b,f[20005],mx,v[20005],dis[20005];
typedef pair<int,int> gr;
vector<gr>edge[100005];
bool dijkstra(int x){
    if(f[1]>x)return 0;
    for(int i=1;i<=n;i++)dis[i]=I,v[i]=0;
    dis[1]=0;
    priority_queue<gr>q;
    q.push({0,1});
    while(q.size()){
        int now=q.top().second;
        q.pop();
        if(v[now]==0){
            v[now]=1;
            for(gr p:edge[now]){
            int w=p.first;
            int to=p.second;
            if(f[to]>x)continue;
            if(dis[to]>dis[now]+w){
                dis[to]=dis[now]+w;
                if(v[to]==0)q.push({-dis[to],to});
            }
        if(to==n){
            if(dis[n]>=b)return 0;
            else return 1;
        }
        }

    }
}
    return 0;
}
/*void twocut(){
    int ans=-1,l=1,r=maxx;
    while(l<=r){
        if(dijkstra(mid))ans=mid,r=mid-1;
        else l=mid+1;
    }
    if(ans==-1)cout<<"AFK";
    else cout<<ans;
}*/
void twocut(){
    int ans=0;
    for(int i=(1<<30);i;i>>=1)if(dijkstra(ans+i)==false)ans+=i;
    if(dijkstra(ans+1))cout<<ans+1;
    else cout<<"AFK";
}
signed main(){
    cin>>n>>m>>b;
    for(int i=1;i<=n;i++)cin>>f[i];
    for(int i=1;i<=m;i++){
        int u,v,w;
        cin>>u>>v>>w;
        edge[u].push_back({w,v});
        edge[v].push_back({w,u});
    }
    twocut();
    return 0;
}

by numberB @ 2024-08-01 18:03:08

最后剩0血也算到达,起点也收费


by lihaoyyy @ 2024-08-03 17:52:46

@numberB 已A,谢谢大佬。


|