#jag2017autumnd. [jag2017autumn_d]Revenge of the Broken Door
[jag2017autumn_d]Revenge of the Broken Door
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 16px; line-height: 18px; background-color: #f5f5f5; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
The JAG Kingdom consists of cities and bidirectional roads. The -th road connects the city and the city with the length . One day, you, a citizen of the JAG Kingdom, decided to go to the city from the city . However, you know that one of the roads in the JAG Kingdom is currently under construction and you cannot pass the road. You don't know which road it is. You can know whether a road is under construction only when you are in either city connected by the road.
Your task is to minimize the total length of the route in the worst case. You don't need to decide a route in advance of departure and you can choose where to go next at any time. If you cannot reach the city in the worst case, output -1
.
Input
The input consists of a single test case formatted as follows.
The first line contains four integers , , , and , where is the number of the cities (), is the number of the bidirectional roads (), is the city you start from (), and is the city you want to reach to (, ). The following lines represent road information: the -th line of the lines consists of three integers , , , which means the -th road connects the cities and (, ) with the length (). You can assume that all the pairs of the cities are connected if no road is under construction. That is, there is at least one route from city to city with given roads, for all cities and . It is also guaranteed that there are no multiple-edges, i.e., for all .
Output
Output the minimum total length of the route in the worst case. If you cannot reach the city in the worst case, output -1
.
Sample Input 1
3 3 1 3
1 2 1
2 3 5
1 3 3
Output for Sample Input 1
6
Sample Input 2
4 4 1 4
1 2 1
2 4 1
1 3 1
3 4 1
Output for Sample Input 2
4
Sample Input 3
5 4 4 1
1 2 3
2 3 4
3 4 5
4 5 6
Output for Sample Input 3
-1