标签:增加 统计 主人公 简单 get main ash line nbsp
#include <bits/stdc++.h> using namespace std; typedef int ll; inline ll read() { ll s=0; bool f=0; char ch=‘ ‘; while(!isdigit(ch)) {f|=(ch==‘-‘); ch=getchar();} while(isdigit(ch)) {s=(s<<3)+(s<<1)+(ch^48); ch=getchar();} return (f)?(-s):(s); } #define R(x) x=read() inline void write(ll x) { if(x<0) {putchar(‘-‘); x=-x;} if(x<10) {putchar(x+‘0‘); return;} write(x/10); putchar((x%10)+‘0‘); } #define W(x) write(x),putchar(‘ ‘) #define Wl(x) write(x),putchar(‘\n‘) const int N=30005,M=200005; int n,m,mxhp,r[30005]; int tot=0,Next[200005],to[200005],val[200005],head[30005]; inline void Link(int x,int y,int z) { Next[++tot]=head[x]; to[tot]=y; val[tot]=z; head[x]=tot; } int tou,wei; struct Node { int x,Hp,dis; }Que[20000005]; int arr[300005]; bool bo[N]; inline int bfs() { int i; tou=1; wei=1; memset(arr,-63,sizeof arr); Que[++wei]=(Node){1,mxhp,0}; arr[1]=mxhp; for(;tou<=wei;) { Node tmp=Que[tou++]; if(tmp.x==n) return tmp.dis; arr[tmp.x]=max(arr[tmp.x],tmp.Hp); for(i=head[tmp.x];i;i=Next[i]) if(tmp.Hp>val[i]) { int oo=min(tmp.Hp-val[i]+r[to[i]],mxhp); if(arr[to[i]]<oo) { arr[to[i]]=oo; Que[++wei]=((Node){to[i],oo,tmp.dis+1}); } } } return -1; } int main() { freopen("game.in","r",stdin); freopen("game.out","w",stdout); int i,x,y,z; R(n); R(m); R(mxhp); for(i=1;i<=n;i++) R(r[i]); for(i=1;i<=m;i++) { R(x); R(y); R(z); if(z<mxhp) {Link(x,y,z); Link(y,x,z);} } Wl(bfs()); return 0; }
标签:增加 统计 主人公 简单 get main ash line nbsp
原文地址:https://www.cnblogs.com/gaojunonly1/p/11252740.html