P1462 通往奥格瑞玛的道路

    xiaoxiao2021-03-25  105

    题目背景

    在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量

    有一天他醒来后发现自己居然到了联盟的主城暴风城

    在被众多联盟的士兵攻击后,他决定逃回自己的家乡奥格瑞玛

    题目描述

    在艾泽拉斯,有n个城市。编号为1,2,3,…,n。

    城市之间有m条双向的公路,连接着两个城市,从某个城市到另一个城市,会遭到联盟的攻击,进而损失一定的血量。

    没经过一个城市,都会被收取一定的过路费(包括起点和终点)。路上并没有收费站。

    假设1为暴风城,n为奥格瑞玛,而他的血量最多为b,出发时他的血量是满的。

    歪嘴哦不希望花很多钱,他想知道,在可以到达奥格瑞玛的情况下,他所经过的所有城市中最多的一次收取的费用的最小值是多少。

    输入输出格式

    输入格式: 第一行3个正整数,n,m,b。分别表示有n个城市,m条公路,歪嘴哦的血量为b。

    接下来有n行,每行1个正整数,fi。表示经过城市i,需要交费fi元。

    再接下来有m行,每行3个正整数,ai,bi,ci(1<=ai,bi<=n)。表示城市ai和城市bi之间有一条公路,如果从城市ai到城市bi,或者从城市bi到城市ai,会损失ci的血量。

    输出格式:

    仅一个整数,表示歪嘴哦交费最多的一次的最小值。

    如果他无法到达奥格瑞玛,输出AFK。

    输入样例#1:

    4 4 8 8 5 6 10 2 1 2 2 4 1 1 3 4 3 4 3

    思路

    O(KE) 将花费二分,求到达目的地最小扣血量,如果大于总血量就不能走。 const ma=1000000; var s:array[1..ma,1..3]of longint; a,b,c,d:array[1..ma]of int64; f:array[1..ma]of boolean; n,m:longint; function spfa(y:longint):boolean; var i,j,g,p,e,h,t:longint; begin h:=0;t:=1; d[1]:=1;f[1]:=true; fillchar(c,sizeof(c),$7f); c[1]:=0; while h<t do begin inc(h); g:=d[h]; e:=b[g]; while e<>0 do begin p:=s[e,1]; if a[p]>y then begin e:=s[e,2]; continue; end; if c[p]>c[g]+s[e,3] then begin c[p]:=c[g]+s[e,3]; if not f[p] then begin inc(t); d[t]:=p; f[p]:=true; end; end; e:=s[e,2]; end; f[g]:=false; end; if c[n]>g then exit(false) else exit(true); end; var z,k:int64; x,y,l,r,mid,i,j:longint; begin readln(n,m,k); for i:=1 to n do begin readln(a[i]); if a[i]>r then r:=a[i]; end; for i:=1 to m do begin readln(x,y,z); inc(j); s[j,1]:=y;s[j,2]:=b[x];b[x]:=j;s[j,3]:=z; inc(j); s[j,1]:=x;s[j,2]:=b[y];b[y]:=j;s[j,3]:=z; end; l:=1; while l<r do begin mid:=(l+r)div 2; if (not spfa(mid))or(a[1]>mid) then l:=mid+1 else r:=mid; end; if spfa(l) then writeln(l) else writeln('AFK'); end.
    转载请注明原文地址: https://ju.6miu.com/read-7242.html

    最新回复(0)