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

#FW0000049. Vận chuyển hàng nặng (Heavy Cargo)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Vận chuyển hàng nặng (Heavy Cargo)

Heavy Cargo

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Undirected roads link named cities and have maximum load capacities. Find a route from the starting city to the destination whose minimum edge capacity is as large as possible.

Input

First n m; then n distinct city names, then m lines cityA cityB capacity, then sourceCity targetCity.

Output

Print the maximum cargo load, or 0 if no route exists.

Subtasks

  • Subtask 1 (40 points): 2≤n≤8, 0≤m≤18, 1≤w≤1002\le n\le 8,\ 0\le m\le 18,\ 1\le w\le 100. The n city names are distinct. Roads are undirected and have different endpoints; parallel roads are allowed.
  • Subtask 2 (60 points): 2≤n≤100, 0≤m≤600, 1≤w≤1062\le n\le 100,\ 0\le m\le 600,\ 1\le w\le 10^6. The n city names are distinct. Roads are undirected and have different endpoints; parallel roads are allowed.

Examples

Input

3 3
A B C
A B 8
B C 5
A C 3
A C

Output

5

Explanation

A–C directly supports load 3; the route A–B–C supports min(8,5)=5, which is optimal.