#P1462. 通往奥格瑞玛的道路

通往奥格瑞玛的道路

Description

There are nn cities in Azeroth, numbered 1,2,3,,n1, 2, 3, \ldots, n.

There are mm undirected roads between cities. Traveling from one city to another will trigger attacks by the Alliance, causing a certain amount of health loss.

Each time he passes through a city, he must pay a toll (including the start and the end). There are no toll booths along the roads.

Assume 11 is Stormwind City, nn is Orgrimmar, and his maximum health is bb. At the start, his health is full. If his health drops below zero, he cannot reach Orgrimmar.

Waizui O does not want to spend too much money. Among all routes that can reach Orgrimmar, consider the maximum single-city toll along the route; find the minimal possible value of this maximum.

Input Format

The first line contains 3 positive integers, n,m,bn, m, b, representing the number of cities, the number of roads, and Waizui O’s health bb.

Then follow nn lines, each containing 1 non-negative integer, fif_i, meaning that passing city ii requires a toll of fif_i.

Then follow mm lines, each containing 3 positive integers, ai,bi,cia_i, b_i, c_i (1ai,bin1\leq a_i,b_i\leq n). This means there is a two-way road between cities aia_i and bib_i. If you travel from city aia_i to city bib_i, or from city bib_i to city aia_i, you will lose cic_i health.

Output Format

Output a single integer: the minimal possible value of the maximum single-city toll along the route.

If he cannot reach Orgrimmar, output AFK.

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

10

Hint

Constraints:

  • For 60%60\% of the testdata, n200n\leq 200, m104m\leq 10^4, b200b\leq 200.
  • For 100%100\% of the testdata, 1n1041\leq n\leq 10^4, 1m5×1041\leq m\leq 5\times 10^4, 1b1091\leq b\leq 10^9.
  • For 100%100\% of the testdata, 1ci1091\leq c_i\leq 10^9, 0fi1090\leq f_i\leq 10^9. There may be two edges connecting the same pair of cities.

Translated by ChatGPT 5