真巧,63分是个什么鬼

P1462 通往奥格瑞玛的道路

三又二分之一 @ 2019-08-18 21:40:03

懵逼63分

#include<iostream>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
struct node{
    int next;
    int to;
    int w;  
}road[500006]; 
priority_queue<int> q;
bool AFK=true;
int head[100006],tot,f[100006],fc[100006],n,m,hp,ans,vis[100006],dis[100006];
void add(int a,int b,int w)
{
    road[++tot].w = w;
    road[tot].to = b;
    road[tot].next = head[a];
    head[a] = tot;
}
bool judge(int fff)
{
    if(f[1] > fff || f[n] > fff)
        return false;
    while(q.size())q.pop();
    memset(vis,0,sizeof(vis));
    for(int i = 1;i<=n;i++)
        dis[i] = 1000000010;

    for(int i = 1;i<=n;i++)
        if(f[i] > fff)
            vis[i] = 1;
    q.push(1);
    dis[1] = 0;
    while(q.size())
    {
        int now = q.top();
        q.pop();
        if(vis[now])
            continue;
        vis[now] = 1;
        for(int i = head[now];i;i=road[i].next)
        {
            if(dis[road[i].to] > dis[now] + road[i].w)
            {
                dis[road[i].to] = dis[now] + road[i].w;
                q.push(road[i].to);
            }
        }
    }
    if(dis[n] > hp)
    {
        return false;
    }
    else
    {
        AFK = false;
        return true;
    }
}
int main()
{
    cin>>n>>m>>hp;
    for(int i = 1;i<=n;i++)
    {
        cin>>f[i];
        fc[i]=f[i];
    }
    sort(fc+1,fc+n+1);
    for(int i = 1;i<=m;i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        add(a,b,c);
        add(b,a,c);
    }
    int l=1,r=n,mid;
    while(l<=r)
    {
        mid = (l+r)/2;
        if(judge(fc[mid]))
        {
            ans = fc[mid];
            r = mid-1;
        }
        else
        {
            l = mid+1;  
        }
    }
    if(AFK)
        cout<<"AFK";
    else
        cout<<ans;
}

by 三又二分之一 @ 2019-08-18 21:49:23

e,现在81分


by 三又二分之一 @ 2019-08-18 21:49:36

这题的数据可是真神奇


|