#P1342. [CERC1998] 请柬

    ID: 339 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>图论福建省历届夏令营最短路

[CERC1998] 请柬

Description

They have printed invitation cards and all the necessary information and plans. Many students are hired to distribute these invitations. Each student volunteer is assigned exactly one bus stop where he or she will stay for the whole day, inviting people to participate.

The bus system here is very special: there are nn stops and mm routes; all routes are one-way, connecting two stops. A bus departs from its origin and, after reaching its destination, returns empty to its origin.

Each morning, the students depart from the headquarters at stop 11, take buses to their assigned stop, and invite passengers there. Exactly one student is scheduled at each stop. At the end of the day, all students return to the headquarters. Now you need to find the minimal possible sum of bus fares required for the students.

Input Format

The first line contains two integers nn and mm.

Lines 22 through m+1m + 1 each contain three integers u,v,wu, v, w, indicating that there is a one-way route from uu to vv with fare ww.

Output Format

Output a single line with one integer, the minimal total fare.

4 6
1 2 10
2 1 60
1 3 20
3 4 10
2 4 5
4 1 50
210 

Hint

Constraints

For 100%100\% of the testdata, it is guaranteed that:

  • 1n,m1061 \leq n, m \leq 10^6.
  • 1u,vn1 \leq u, v \leq n, 1w1091 \leq w \leq 10^9.
  • Every stop is reachable from 11.

Translated by ChatGPT 5