Poisonous Labyrinth
시간 제한3초메모리 제한2048 MB
가중치 트리에서 각 독 종류마다 두 병이 놓여 있을 때, 모든 쌍을 마시고 돌아오는 최소 왕복 거리를 주는 시작 정점을 찾는다.
문제
BThero needs to escape from a labyrinth which is represented by a tree with vertices and edges, where each edge has its own length. Additionally, the labyrinth vertices contain poison vials: two vials of each of the different types of poison.
When BThero enters a vertex for the first time, he immediately drinks all the vials in that vertex. When he ends up in a vertex where he has been before, there are no more vials to drink there.
When BTHero drinks a vial of some type of poison that he did not yet drink, he is poisoned by that type of poison. To cure it, BThero must find and drink the other vial of the same type of poison.
BThero starts his path in vertex , where he immediately drinks all the vials in that vertex. Then he passes through some vertices until he is no longer poisoned, after which he returns to vertex and leaves the labyrinth.
It is necessary to find the starting vertex such that, if BThero starts his path in this vertex, he will have to travel the minimum total distance, provided that he chooses the optimal route.
입력
The first line contains two integers and (, ): the number of vertices in the labyrinth and the number of types of poisons.
Each of the next lines contains three integers, , , and (, ) which describe a bidirectional edge between vertices and with length .
Each of the next lines contains two integers and (): the two vertices where the vials with poison of type are located. Note that it is possible that , in which case, when entering the vertex, BThero is poisoned and then cured immediately.
출력
Output a line with a single integer: the minimum distance that BThero will have to travel to cure himself from all poisons if he starts from the optimal vertex.