QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 512 MB Points totaux : 100

#14451. Mountain Climbing

Statistiques

Little C likes mountain climbing, but his physical stamina is average, and he cannot climb too high continuously. Today, Little C decides to climb Bit Peak. There are $n$ scenic spots on Bit Peak, and the altitude of the $i$-th spot is $h_i$ meters. There are $m$ bidirectional paths between the spots. The $i$-th path connects spot $u_i$ and spot $v_i$, and it takes $t_i$ minutes for Little C to traverse the $i$-th path in either direction. Little C accumulates fatigue while climbing. His initial fatigue is $0$, and the maximum fatigue he can tolerate is $H$. Suppose Little C is currently at spot $x$, and there is a path from spot $x$ to spot $y$: If the altitude of spot $x$ is higher than that of spot $y$, this is an easy downhill path. If Little C chooses to take this path, his stamina is restored, and his fatigue is reset to $0$. Otherwise, if Little C chooses to take this path, his fatigue increases by $h_y - h_x$. Little C can only take this path if his accumulated fatigue does not exceed $H$.

Now, Little C starts from spot $1$ and can only move between spots using these paths. For each spot, Little C wants to know the minimum time in minutes required to reach it, or if it is impossible to reach.

Input

The first line contains three positive integers $n, m, H$ ($2 \le n \le 10^4, 0 \le m \le 2 \times 10^4, 1 \le H \le 100$), representing the number of spots, the number of paths, and the maximum fatigue Little C can tolerate, respectively. The second line contains $n$ positive integers $h_1, h_2, \dots, h_n$ ($1 \le h_i \le 10^9$), representing the altitude of each spot. The next $m$ lines each contain three positive integers $u_i, v_i, t_i$ ($1 \le u_i, v_i \le n, u_i \neq v_i, 1 \le t_i \le 10^9$), representing the two spots connected by a path and the time required to traverse it.

Output

Output a single line containing $n-1$ integers. The $i$-th integer represents the minimum time (in minutes) required for Little C to reach the $(i+1)$-th spot. If Little C can never reach that spot, output $-1$.

Examples

Input 1

6 7 3
1 2 3 4 5 6
1 2 1
2 4 10
1 3 8
2 3 2
3 5 9
4 3 100
2 6 2

Output 1

1 3 11 16 -1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.