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

#FW0000074. Chiến tranh và hậu cần (Warfare And Logistics)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chiến tranh và hậu cần (Warfare And Logistics)

Warfare And Logistics

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

An undirected logistics network has a positive cost on each edge. The cost for an ordered pair (i,j)(i,j) is its shortest-path cost, or LL if unreachable. Compute the total before an attack and the maximum total obtained by deleting exactly one individually indexed road.

Input

First n,m,Ln,m,L, then mm undirected weighted roads u,v,wu,v,w using 1-based indices. Parallel roads are allowed.

Output

Print two integers: the total before deletion and the maximum total after one deletion.

Subtasks

  • Subtask 1 (40 points): 2≤n≤5, 1≤m≤102\le n\le 5,\ 1\le m\le 10. 1≤L≤1081\le L\le10^8, 1≤w≤10001\le w\le1000; đường vô hướng, có thể có cạnh trùng.

  • Subtask 2 (60 points): 2≤n≤9, 1≤m≤202\le n\le 9,\ 1\le m\le 20. 1≤L≤1081\le L\le10^8, 1≤w≤10001\le w\le1000; đường vô hướng, có thể có cạnh trùng.

Examples

Input

3 3 100
1 2 2
2 3 3
1 3 10

Output

20 52

Explanation

Original distances over unordered pairs are 2, 3, and 5; ordered-pair sum is 20. Removing road 1–2 changes them to 13, 3, and 10, for a total of 52.