#P1629. 邮递员送信

邮递员送信

Description

There is a postman who needs to deliver items, and the post office is at node 11. He needs to deliver n1n-1 items, with destinations at nodes 22 through nn. Because the city’s traffic is busy, all roads are one-way, with a total of mm roads. The postman can carry only one item at a time, and after delivering each item, he must return to the post office. Find the minimum time needed to deliver all n1n-1 items and finally return to the post office.

Input Format

The first line contains two integers, nn and mm, denoting the number of nodes and roads in the city.

From the second line to the (m+1)(m+1)-th line, each line contains three integers u,v,wu,v,w, indicating there is a one-way road from uu to vv with travel time ww.

Output Format

Output a single line containing one integer, the minimum required time.

5 10
2 3 5
1 5 5
3 5 6
1 2 8
1 3 8
5 3 4
4 1 8
4 5 3
3 5 6
5 4 2
83

Hint

Constraints:

  • For 30%30\% of the testdata, 1n2001 \leq n \leq 200.
  • For 100%100\% of the testdata, 1n1031 \leq n \leq 10^3, 1m1051 \leq m \leq 10^5, 1u,vn1 \leq u,v \leq n, 1w1041 \leq w \leq 10^4. The input guarantees that any two nodes can reach each other (the directed graph is strongly connected).

Translated by ChatGPT 5