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

#FW0000020. Cuộc thi gặp mặt (A Contest to Meet)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Cuộc thi gặp mặt (A Contest to Meet)

A Contest to Meet

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Three contestants start at arbitrary intersections and must eventually meet at an arbitrary intersection, also not known in advance. Each walks along a shortest route at their own speed. Find the smallest integer broadcast duration that suffices for every possible combination of starting locations and meeting location. Early arrivals may wait.

Input

n,mn,m, followed by mm undirected lengths u,v,du, v, d using zero-based vertices, then three speeds.

Output

Print the minimum sufficient integer number of minutes.

Subtasks

  • Subtask 1 (40 points): n≤6n\le 6; 1≤n≤1001\le n\le 100; 0≤m≤90000\le m\le 9000; 0≤u,v<n0\le u,v<n; 1≤d≤2001\le d\le 200; 50≤sA,sB,sC≤10050\le s_A,s_B,s_C\le 100; the graph is connected.
  • Subtask 2 (60 points): 1≤n≤1001\le n\le 100; 0≤m≤90000\le m\le 9000; 0≤u,v<n0\le u,v<n; 1≤d≤2001\le d\le 200; 50≤sA,sB,sC≤10050\le s_A,s_B,s_C\le 100; the graph is connected.

Examples

Input

2 1
0 1 150
60 50 75

Output

3

Explanation

The diameter is 150150 meters and the slowest contestant walks at 5050 meters/minute, so the worst-case travel time is 150/50=3150/50=3 minutes.