Valley 1462 Road leading to Orgrimmar
Address: http://www.luogu.org/problem/show?pid=1462
Ideas:
First judge the situation of AFK, take the blood weight as the weight, use the SPFA algorithm to calculate the shortest path, check whether the blood volume is greater than 0 to reach the end.
Then, the tolls of each city are ordered, using dichotomy to try in order to go through each city without exceeding a certain cost, and reach the end of the blood volume is greater than 0.
1#include <cstdio>2#include <string.h>3#include <deque>4#include <algorithm>5 using namespacestd;6 Const intN = 1e4+Ten, M = 1e5+Ten;7 Const Long Long intINF = (1ll<< A)-1;8 intU[m], v[m], w[m], first[n], next[m], money[n], N, M, HP, A[n];9 Long Long intD[n];Ten BOOLcmpConst intAConst intb) { One returnMoney[a] <Money[b]; A } - BOOLSPFA (intCash) - { the for(intI=1; i<n; ++i) -D[i] =INF; -d[0] =0; - BOOLCnt[n] = {0}; +cnt[0] =true; -deque<int>dq; + intT; ADq.push_back (0); at while(!dq.empty ()) - { -t =Dq.front (); - Dq.pop_front (); - for(intX=FIRST[T]; ~x; x=Next[x]) - { in if(D[v[x] > D[u[x]] + w[x] && Money[v[x]] <=Cash) - { toD[V[X]] = d[u[x]] +W[x]; + if(!Cnt[v[x]]) - { the if(!dq.empty () && D[v[x]] <D[dq.front ()]) * Dq.push_front (v[x]); $ ElsePanax Notoginseng Dq.push_back (v[x]); -CNT[V[X]] =true; the } + } A } theCNT[T] =false; + } - returnd[n-1] > HP?false:true; $ } $ voidSolvevoid) - { - if(! SPFA (1<< -)) the { -printf"afk\n");Wuyi return ; the } - intL=0, r=n-1, Mid, ans =1<< -; Wu while(l<=R) - { AboutMid = (l+r) >>1; $ if(SPFA (Money[a[mid])) -ans = Money[a[mid]], r = mid-1; - Else -L = mid+1; A } +printf"%d\n", ans); the } - intMainvoid) $ { the while(~SCANF (" %d%d%d", &n, &m, &hp)) the { thememset (First,-1,sizeof(first)); the for(intI=0; i<n; ++i) - { inA[i] =i; thescanf"%d", money+i); the } AboutSort (A, A +N, CMP); the for(intI=0; i<2*m; ++i) the { thescanf" %d%d%d", U+i, V+i, w+i); +--u[i],--V[i]; -Next[i] =First[u[i]]; theFirst[u[i]] = i++;BayiU[i] = v[i-1], v[i] = u[i-1], w[i] = w[i-1]; theNext[i] =First[u[i]]; theFirst[u[i]] =i; - } - solve (); the } the}
Valley 1462 Road leading to Orgrimmar