求大佬,5,8,11过不去,看了下别人的代码,也没找出来

P1462 通往奥格瑞玛的道路

yu55555 @ 2019-08-23 19:54:20

#include<bits/stdc++.h>
#define ll long long
#define debug(x) cout<<"["<<x<<"]" <<endl;
#define mem(a,b) memset(a,b,sizeof(a));
#define f(x,y) for(int x=1;x<=y;x++)
using namespace std;
const int mx=10000+5;
int n,m,flag;
ll b,f[mx],f2[mx],dis[mx];
struct node{
    int x;
    ll d;
    node(int _x,ll _d){
        x=_x;
        d=_d;
    }
    bool operator < (const node& r)const{
        return d>r.d;
    }
};
vector<node>edge[mx];
bool book[mx];
bool dj(int x){
    if(x<f[1]||x<f[n])return false;
    priority_queue<node>q;
    mem(dis,0x3f);
    dis[1]=0;
    q.push(node(1,0));
    while(!q.empty()){
        node u=q.top();
        q.pop();
        if(u.x==n){
            return b>=dis[n];
        }
        if(book[u.x])continue;
        book[u.x]=1;
        for(int i=0;i<edge[u.x].size();i++){
            node y=edge[u.x][i];
            if(dis[y.x]>y.d+u.d&&f[y.x]<=x){
                dis[y.x]=y.d+u.d;
                q.push(node(y.x,dis[y.x]));
            }
        }
    }

}
int main(){
//  freopen("testdata.in","r",stdin);
    cin>>n>>m>>b;
    f(i,n){
        cin>>f[i];
        f2[i]=f[i];
    }
    sort(f2+1,f2+n+1,greater<ll>());
    int a1,b1;
    ll c1;
    f(i,m){
        cin>>a1>>b1>>c1;
        if(a1==b1)continue;
        edge[a1].push_back(node(b1,c1));
        edge[b1].push_back(node(a1,c1));
    }
    int l=1,r=n,mid=0,ans;
    if(!dj(f2[1])){
        cout<<"AFK";
        return 0;
    }
    ans=1;
    while(l<=r){
        mid=(l+r)>>1;
        if(dj(f2[mid])){
            ans=mid;
            l=mid+1;

        }
        else r=mid-1;
    }
    cout<<f2[ans];

    return 0;
}

by win_or_die @ 2019-08-23 22:29:50

我这道题也是跟你一样,查了好久(还是面向代码差错。。),查出来一样,可就是WA。。


|