#P5340. [TJOI2019] 大中锋的游乐场

[TJOI2019] 大中锋的游乐场

Problem Description

Big Center Forward is playing in an amusement park. There are nn attractions in the park, connected by a total of mm roads. Traveling along each road takes a certain amount of time. For the convenience of visitors, each attraction has a snack shop next to it: some shops sell cola, and the others sell hamburgers.

Because Big Center Forward loves eating, every time he arrives at an attraction, he will first buy either a cup of cola or a hamburger and consume it. However, if the number of hamburgers he has eaten exceeds the number of colas he has drunk by more than kk, he will feel very thirsty; if the number of colas he has drunk exceeds the number of hamburgers he has eaten by more than kk, he will feel very hungry.

Now Big Center Forward is at attraction aa and wants to go to attraction bb, but he does not want to feel very thirsty or very hungry during the trip. He wants to know the minimum total time spent on the way. Since Big Center Forward is very lazy and does not want to think about it, can you help him solve this problem?

Note: Big Center Forward is extremely greedy, so the first thing he does upon arriving at each node is to eat (or drink), and only then consider other things. Therefore, he will buy a hamburger (or cola) at both the starting point and the ending point as well. You also need to ensure that at these two nodes he will not feel very hungry or very thirsty.

Input Format

The first line contains an integer TT, indicating the number of test cases. For each test case, the format is as follows.

The first line contains three integers nn, mm, and kk, representing the number of attractions, the number of roads, and the given parameter kk as described in the statement.

The second line contains nn integers. The ii-th integer aia_i indicates the item sold by the shop next to attraction ii: 11 means cola, and 22 means hamburger.

Lines 33 to (m+2)(m + 2) each contain three integers u,v,wu, v, w, indicating that there is an undirected road between attraction uu and attraction vv, and traveling along this road takes time ww.

Line m+3m + 3 contains two integers s,ts, t, indicating that Big Center Forward wants to travel from attraction ss to attraction tt.

Output Format

For each test case, output one line containing one integer, the answer. If there is no feasible solution, output 1-1.

1
2 1 1
1 1
1 2 1
1 2
-1
1
2 1 2
1 1
1 2 1
1 2
1

Hint

Constraints

  • For 30%30\% of the testdata, n50,m1000n\leq 50, m\leq 1000.
  • For 100%100\% of the testdata, 1n100001 \leq n\leq 10000, 1m1000001 \leq m\leq 100000, 1k101 \leq k\leq 10, 1ai21 \leq a_i \leq 2, 1u,v,s,tn1 \leq u, v, s, t \leq n, 1w100001 \leq w \leq 10000.

For all testdata, 1T101 \leq T \leq 10, and in each test point, the number of large testdata cases does not exceed 22.

Additional Notes

  • The path is not necessarily a simple path.
  • Big Center Forward may pass through a node multiple times, and each time he will obtain a hamburger/cola.

Translated by ChatGPT 5