再次求助...怎么办45

P1462 通往奥格瑞玛的道路

wxy_god @ 2018-10-02 08:19:11

我是评测记录

#include <bits/stdc++.h>

using namespace std;

int const N = 100010;
int const INF = 1e9 + 10;
int n, m, b, tot, he, ta, f[N], g[N], target[N], prev[N], last[N], v[N], q[N * 10];

void add (int a, int b, int c) {
    target[++tot] = b;
    prev[tot] = last[a];
    last[a] = tot;
    v[tot] = c;
}

bool check (int now) {
    if(f[0] > now || f[n - 1] > now)
    {
        return false;
    }

    for(int i = 0; i < n; i ++ )
    {
        g[i] = INF;

        he = 0, ta = 0, q[0] = 0, g[0] = 0;

        while(he <= ta)
        {
            int x = q[he++], ptr = last[x];

            while(ptr != 0)
            {
                int y = target[ptr];

                if(f[y] <= now && g[y] > g[x] + v[ptr])
                {
                    q[++ta] = y;
                    g[y] = g[x] + v[ptr];
                }

                ptr = prev[ptr];

            }

        } 

    }

    if(g[n] <= b)
    {
        return true;
    }

    return false;

}

int main () {

    scanf("%d%d%d", &n, &m, &b);

    for(int i = 0; i < n; i ++ )
    {
        scanf("%d", &f[i]);
    }

    for(int i = 0; i < m; i ++ )
    {
        int a, b, c;

        scanf("%d%d%d", &a, &b, &c);

        a -- ;
        b -- ;
        c -- ;

        add(a, b, c);
        add(b, a, c);

    }

    int l = 0, r = 1e9 + 1;

    while(r - l > 1)
    {
        int mid = (l + r) / 2;
        if(check(mid) == true)
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }

    if(check(l) == true)
    {
        printf("%d", l);
    }
    else
    {
        if(check(r) == true)
        {
            printf("%d", r);
        }
        else
        {
            printf("AFK");
        }
    }

    return 0;
}

by wxy_god @ 2018-10-02 08:27:23

都过了一道题了还没人帮我吗


by WA鸭鸭 @ 2018-10-02 08:29:11

@我是一个垃圾 您太强了


by wxy_god @ 2018-10-02 08:29:59

@WA鸭鸭 说反了


by WA鸭鸭 @ 2018-10-02 08:31:07

@我是一个垃圾 哦,那就是我好菜啊


by wxy_god @ 2018-10-02 08:56:29

真的没人吗


by WA鸭鸭 @ 2018-10-02 09:02:02

@我是一个垃圾 没人有鸭,但是我不会


by uwagjaynoi @ 2018-10-02 18:50:07

@我是一个垃圾 爆int了吧


by wxy_god @ 2018-10-02 20:37:26

@Goblinmagupta 谢谢我试试


|