#P17184. [ICPC 2017 Hong Kong R] Card collection

[ICPC 2017 Hong Kong R] Card collection

Problem Description

In an online game, a player can collect different types of power cards. Each power card can enable a player to have a unique game magic. There are mm power cards available in the game as (P1,,Pm)(P_1, \dots, P_m). A power card can be acquired by game points or through trading with others. In order to support trading easier, a platform has been built. The platform charges a fixed amount Ci,jC_{i,j} game points for trading respective power cards PiP_i and PjP_j. Note: Trading PiP_i to PjP_j or PjP_j to PiP_i would be of the same charge.

Write a program to calculate the minimal number of game points with a given original power card (PoP_o) to a target one (PtP_t). The output of your program should be the minimal game point value.

Input Format

The test data may contain many test cases. Each test case contains three data sections. The first section is an integer to indicate the number of power card types mm (1<m501 < m \le 50). The second section contains two integers representing the original power card PoP_o (0<Pom0 < P_o \le m) and the target power card PtP_t (0<Ptm0 < P_t \le m). Also, PoP_o cannot be the same as PtP_t. The third section has a set of triplets and each triplet contains two cards id ii, jj and the charge amount ci,jc_{i,j} (0<ci,j200 < c_{i,j} \le 20) between 22 types of power cards (Pi,Pj)(P_i, P_j). The end part of section 33 contains a single 00.

Output Format

The output for each test case is the minimal number of game points needed for the trading.

5
2 4
1 2 1
2 3 4
5 4 2
3 4 1
2 5 2
0
7
6 7
1 2 4
1 3 2
1 6 1  
2 7 1
3 4 2
4 7 1
4 5 1
5 6 2
0
4
4