logo AlgoBeat OnlineJudge
登录 注册

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

内存限制:512 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 power cards available in the game as . 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 game points for trading respective power cards and . Note: Trading to or to would be of the same charge.

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

输入格式

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 (). The second section contains two integers representing the original power card () and the target power card (). Also, cannot be the same as . The third section has a set of triplets and each triplet contains two cards id , and the charge amount () between types of power cards . The end part of section contains a single .

输出格式

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

样例

样例输入 1

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

样例输出 1

4
4