PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000425. Chọn pin cho xe điện (Charles in Charge)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chọn pin cho xe điện (Charles in Charge)

Charles in Charge

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Charles commutes between his home in city 11 and his workplace in city nn using highways. He wants an electric car. The available cars differ only in battery size; a larger battery costs more. He can recharge fully in any city but not between cities. Charging time is negligible.

There are nn cities numbered 11 through nn and mm two-way highways. Highway ii joins cities ui,viu_i,v_i, has length wiw_i, and passes through no other city.

Let DD be the shortest total route length between home and work without battery restrictions. His wife Charlotte accepts a longer commute provided its length does not exceed D(1+x/100)D(1+x/100), where xx is a given percentage.

A car with range bb after a full charge can traverse only highways of length at most bb. Find the minimum bb for which a route from city 11 to city nn meets the total length limit. Since highways are bidirectional, the result also applies to the return journey.

Input

The first line contains integers n,m,xn,m,x: the number of cities, number of highways, and allowed percentage increase in route length.

Each of the next mm lines contains three integers ui,vi,wiu_i,v_i,w_i, the endpoints and length of highway ii.

Output

Print a single integer: the minimum distance the car must be able to travel on one full charge.

Subtasks

  • Subtask 1 (20 points): 2≤n≤202\le n\le 20; 1≤m≤501\le m\le 50; 0≤x≤100000\le x\le 10000; 1≤ui,vi≤n1\le u_i,v_i\le n; 1≤wi≤1091\le w_i\le 10^9; for every 1≤i≤m1\le i\le m. Highways are bidirectional; a route from 11 to nn exists.
  • Subtask 2 (30 points): 2≤n≤100002\le n\le 10000; 1≤m≤1000001\le m\le 100000; x=0x=0; 1≤ui,vi≤n1\le u_i,v_i\le n; 1≤wi≤1091\le w_i\le 10^9; for every 1≤i≤m1\le i\le m. Highways are bidirectional; a route from 11 to nn exists.
  • Subtask 3 (50 points): 2≤n≤100002\le n\le 10000; 1≤m≤1000001\le m\le 100000; 0≤x≤100000\le x\le 10000; 1≤ui,vi≤n1\le u_i,v_i\le n; 1≤wi≤1091\le w_i\le 10^9; for every 1≤i≤m1\le i\le m. Highways are bidirectional; a route from 11 to nn exists.

Examples

Input 1

2 1 100
1 2 5

Output 1

5

Explanation 1

The only highway has length 5. A charge must cover the entire highway, so the required range is 5.

Input 2

9 8 15
1 9 16
1 4 4
4 5 4
5 6 4
6 8 4
4 7 5
7 8 5
8 9 4

Output 2

5

Explanation 2

The direct route is 16, giving a limit of 16⋅1.15=18.416\cdot1.15=18.4. Route 1,4,7,8,91,4,7,8,9 has length 4+5+5+4=184+5+5+4=18 and maximum highway length 5. With range 4, the only simple route has length 20, exceeding the limit. Hence the answer is 5.

Highway routes

Input 3

9 8 30
1 9 16
1 4 4
4 5 4
5 6 4
6 8 4
4 7 5
7 8 5
8 9 4

Output 3

4

Explanation 3

The limit is now 16⋅1.30=20.816\cdot1.30=20.8. Route 1,4,5,6,8,91,4,5,6,8,9 uses five highways of length 4, for a total of 20. No highway is shorter than 4, so a smaller range cannot work.

Adapted from Charles in Charge, BAPC 2016 Jury, under CC BY-SA 4.0.