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

#FW0000100. Đi chung xe (Carpool)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đi chung xe (Carpool)

Carpool

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

There are PP passengers waiting at intersections 1..P1..P, sharing starting depot 00 and destination P+1P+1. Use the minimum number of cars needed, each carrying at most five passengers. A car can choose its pickup order, then proceed to the destination, spending an additional 55 minutes at each passenger pickup. All cars operate in parallel. Minimize the finishing time of the last car.

Input

First line P,mP,m, followed by mm bidirectional roads u,v,wu,v,w between vertices 0..P+10..P+1.

Output

Print minimum time for all passengers to arrive.

Subtasks

  • Subtask 1 (40 points): 1≤P≤51\le P\le 5. All input-format and graph conditions above apply.

  • Subtask 2 (60 points): 1≤P≤101\le P\le 10. All input-format and graph conditions above apply.

Examples

Input

1 2
0 1 3
1 2 4

Output

12

Explanation

One car picks up passenger 1: depot 0 to pickup 1 takes 3 minutes, pickup 1 to office 2 takes 4, plus 5 minutes overhead, totaling 3+4+5=123+4+5=12.