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

#FW0000073. Quy hoạch giao thông (Transportation Planning)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Quy hoạch giao thông (Transportation Planning)

Transportation Planning

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

For a connected city network where each undirected road has Euclidean travel time, choose one missing road minimizing the sum of shortest travel times across all unordered pairs. Break ties by the lowest endpoint indices. Report if no addition improves the network.

Input

First nn, followed by nn integer coordinates (0-based vertices), then mm and mm undirected roads u,vu,v. All intersections are connected, and roads are unique.

Output

Print no addition reduces X if no improvement, otherwise adding u v reduces X to Y, where X,YX,Y are the original and updated totals with 10 decimal digits.

Subtasks

  • Subtask 1 (40 points): 2≤n≤72\le n\le 7. n−1≤m≤n(n−1)/2n-1\le m\le n(n-1)/2, −500≤xi,yi≤500-500\le x_i,y_i\le500; tọa độ phân biệt, đồ thị liên thông.

  • Subtask 2 (60 points): 2≤n≤202\le n\le 20. n−1≤m≤n(n−1)/2n-1\le m\le n(n-1)/2, −500≤xi,yi≤500-500\le x_i,y_i\le500; tọa độ phân biệt, đồ thị liên thông.

Examples

Input

3
0 0
0 3
4 0
2
0 1
1 2

Output

adding 0 2 reduces 16.0000000000 to 12.0000000000

Explanation

Initially the three pairwise distances are 3, 5, and 8, summing to 16. Adding road 0–2 of length 4 cuts the last distance by 4 and lowers the total to 12.