#P2009. 跑步

跑步

Description

Chang Sheniu’s running field is a polygon (number of sides 20\leq 20, each vertex is denoted by an uppercase English letter). Inside the polygon, there are also some trails that connect two non-adjacent vertices. All edges and trails are bidirectional. For example, in the figure below:

Suppose Chang Sheniu runs from AA to DD, the shortest path is AEDA-E-D (length 66).

You are given the number of sides nn, the length of each polygon edge, the number of internal connections kk, the two endpoints and the length of each internal connection, and the start and end vertices. Please output the length of the shortest path. However, Chang Sheniu has a bit of OCD: if there are multiple roads directly connecting the same pair of vertices, he will choose the longest one.

Note: The input does not guarantee that the start and end vertices are different, nor that the endpoints of an internal trail are different. When reading the input, if there are multiple internal trails between two vertices, the distance between them is the maximum of those trails. Therefore, if an internal trail starts and ends at the same vertex, the distance from that vertex to itself is not 00.

Description

Input Format

  • The first line contains 22 numbers, n,kn, k.
  • The second line contains nn numbers, giving the lengths of the polygon’s edges in clockwise order, i.e., the lengths of AB,BC,CD,DE,AB, BC, CD, DE, \ldots.
  • Each of the following kk lines contains two letters and a number. The two letters are the endpoints of an internal connection, and the number is its length.
  • The last line contains two letters, the start and end vertices of the run.

Within each line, letters and numbers are separated by a single space.

Output Format

One line with one number: the length of the shortest path.

5 2
6 4 5 4 2
A D 7
E B 8
A D
6

Hint

  • For 20%20\% of the testdata, k=0k = 0.
  • For 50%50\% of the testdata, k10k \leq 10.
  • For 100%100\% of the testdata, 1n201 \leq n \leq 20, 0k1000 \leq k \leq 100, and all path lengths do not exceed 10001000.

Translated by ChatGPT 5