3400. Admiral

单点时限: 1.0 sec

内存限制: 256 MB

Michiel Adriaenszoon de Ruyter is the most famous admiral in Dutch history and is well known for his role in the Anglo-Dutch Wars of the 17th century. De Ruyter personally commanded a flagship and issued commands to allied warships during naval battles.

In De Ruyter’s time, graph theory had just been invented and the admiral used it to his great advantage in planning his naval battles. Waypoints at sea are represented by vertices, and possible passages from one waypoint to another are represented as directed edges. Given any two waypoints $W_1$ and $W_2$, there is at most one passage $W_1$ → $W_2$. Each directed edge is marked with the number of cannonballs that need to be fired in order to safely move a ship along that edge, sinking the enemy ships encountered along the way.

One of De Ruyter’s most successful tactics was the De Ruyter Manoeuvre. Here, two warships start at the same waypoint, and split up and fight their way through the enemy fleet, joining up again at a destination waypoint. The manoeuvre prescribes that the two warships take disjunct routes, meaning that they must not visit the same waypoint (other than the start and end-points), or use the same passage during the battle.

Being Dutch, Admiral De Ruyter did not like to waste money; in 17th century naval warfare, this meant firing as few expensive cannonballs as possible.

Figure 1: A particular instance of De Ruyter’s tactic, visualised as a graph. Two ships (‘red’ and ‘blue’) move from a shared starting point (1) to a shared endpoint (6). The red ship’s route is 1 → 3 → 6 (firing 33 canonballs along the way); the blue ship’s route is 1 → 2 → 5 → 4 → 6 (firing 53 canonballs along the way). In total, 86 canonballs are fired during the manoeuvre. Except for the start- and end-point, no vertices or edges are visited by both ships.

输入格式

For each test case, the input consists of:

  • A line containing two integers $v$ $(3 \le v \le 1000)$ and $e$ $(3 \le e \le 10000)$, the number of waypoints and passages, respectively.
  • Then, $e$ lines follow: for each passage, a line containing three integers:
    1. $a_i$ $(1 \le a_i \le v)$, the starting-point of a passage, which is represented by a waypoint;
    2. $b_i$ $(1 \le b_i \le v)$ and $(a_i \neq b_i)$, the end-point of a passage, which is represented by a waypoint. All passages are directed passages;
    3. $c_i$ $(1 \le c_i \le 100)$, the number of cannonballs that are fired when travelling along this passage.

The starting waypoint is $1$ and the destination waypoint is $v$. There are always at least two disjunct routes from waypoint $1$ to waypoint $v$.

输出格式

For each test case, the output consists of a single positive integer: the smallest possible sum of cannonballs fired by both ships when reaching the destination waypoint.

样例

Input
6 11
1 2 23
1 3 12
1 4 99
2 5 17
2 6 73
3 5 3
3 6 21
4 6 8
5 2 33
5 4 5
6 5 20
Output
86

2 人解决,2 人已尝试。

3 份提交通过,共有 8 份提交。

8.3 EMB 奖励。

创建: 2 年,10 月前.

修改: 2 年,10 月前.

最后提交: 2 年,5 月前.

来源: NWERC 2012

题目标签