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

#FW0000083. Lộ trình xe buýt rẻ nhất (Cheapest way)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Lộ trình xe buýt rẻ nhất (Cheapest way)

Cheapest way

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

A bus company operates named stations with a fee charged at every visited station, including endpoints. Every kilometre of undirected road costs 2 taka. Add 10% profit to the minimum itinerary cost, then divide by the stated bus seat count. For each query output a cheapest station sequence and the price per seat.

Input

First nn named stations and their fees; then mm undirected roads stationA stationB kilometres; then qq requests source target seatCount. Station names are distinct tokens, and seat count is positive.

Output

For each query print the station names on a minimum-cost path, then Each passenger has to pay : X.XX taka, with exactly two decimal digits.

Subtasks

  • Subtask 1 (40 points): 2≤n≤6, 1≤q≤42\le n\le 6,\ 1\le q\le4. 1≤n≤121\le n\le12, n−1≤m≤n(n−1)/2n-1\le m\le n(n-1)/2, mạng liên thông, phí trạm và số km nguyên dương ≤1000\le1000, 1≤seats≤1031\le seats\le10^3.

  • Subtask 2 (60 points): 2≤n≤12, 1≤q≤72\le n\le 12,\ 1\le q\le7. 1≤n≤121\le n\le12, n−1≤m≤n(n−1)/2n-1\le m\le n(n-1)/2, mạng liên thông, phí trạm và số km nguyên dương ≤1000\le1000, 1≤seats≤1031\le seats\le10^3.

Examples

Input

3
A 5
B 8
C 10
3
A B 12
B C 10
A C 30
2
A C 30
A B 30

Output

A B C
Each passenger has to pay : 2.46 taka
A B
Each passenger has to pay : 1.36 taka

Explanation

Route A B C covers 22 km, costing 44 taka in fuel; station fees total 23. With 10% profit and 30 seats the fare is 67×1.1/30=2.46 after rounding.