Two Bugcats are planning to meet up for a gathering. The map they live on consists of $$$n$$$ nodes and $$$m$$$ directed edges. The first Bugcat starts at Node $$$1$$$, and the second Bugcat starts at Node $$$n$$$.
Each edge $$$i$$$ connects node $$$x_i$$$ to node $$$y_i$$$. There are two ways to traverse an edge:
The two Bugcats have a combined total budget of $$$w$$$ dollars. They can choose to take a taxi on any edge at any time, provided they do not exceed their total budget.
Your task is to find the minimum total stamina the two Bugcats must consume in order to meet at the same node, given their budget constraint.If it is impossible for the two Bugcats to meet, output $$$-1$$$.
The input uses multiple test cases.
The first line contains an integer $$$T$$$, the number of test cases.
For each test case, the first line contains three integers $$$n, m, w$$$ ($$$\sum n, \sum m \le 1000, 0 \le w \le 1000$$$), representing the number of nodes, the number of edges, and the total budget.
The next $$$m$$$ lines each contain three integers $$$x_i, y_i, z_i$$$ ($$$1 \le x_i, y_i \le n, 1 \le z_i \le 10^9$$$), representing a directed edge from $$$x_i$$$ to $$$y_i$$$ with a walking stamina cost of $$$z_i$$$.
For each test case, output a single line representing the minimum combined stamina required for the two Bugcats to meet.If it is impossible for the two Bugcats to meet, output $$$-1$$$.
25 5 21 2 31 3 45 4 24 3 12 3 1005 4 21 2 31 3 45 4 22 3 100
1 -1
| Название |
|---|


