There and Back Again
시간 제한2초메모리 제한1024 MB
도시 1과 n 사이를 잇는 두 경로의 사용 도로 집합이 서로 다르도록 하면서 총 이동 시간을 최소로 만드는 값을 구하거나 -1을 출력한다.
문제
There are cities in Asia-Pacific, numbered from to . The 2024 ICPC Asia Pacific Championship is held in Hanoi, which is city .
There are bidirectional roads, numbered from to , connecting some pairs of cities. Road connects cities and and takes units of time to travel in either direction. Each road connects different cities and different roads connect different pairs of cities.
You live in city . You would like to travel to city to attend the contest through a sequence of roads, and then travel back to city through a sequence of roads. Traveling through the same route is boring, so you would like the routes in both traversals to be different. Two routes are considered different if the set of distinct roads traversed through one route is different from the set of distinct roads traversed through the other route.
In each traversal, it is possible to pass through the same city or road multiple times. It is also possible to continue traversing after reaching the destination city (i.e., city or city ). The traversal time is the sum of the travel times of the roads passed through in the traversal. If a road is passed through multiple times in the traversal, then the travel time of the road is also counted multiple times accordingly.
Determine the minimum total traversal time to do both traversals satisfying the requirements above, or indicate if the requirements cannot be satisfied.
입력
The first line of input contains two integers and (; ). Each of the next m lines contains three integers. The -th line contains , , and (; ). Different roads connect different pairs of cities.
출력
Output an integer representing the minimum total traversal time to do both traversals satisfying the requirements above, or -1 if the requirements cannot be satisfied.