#P1476. 休息中的小呆

休息中的小呆

Description

While everyone is being tested (tortured?) in the exam room, Xiao Dai is leisurely (annoyingly) playing a game called "Initial Dream." The game tells the story of an aspiring young man named pass who travels through different times and spaces to fight the legendary demon king chinesesonic. Xiao Dai finds the game's story flow quite complex. It has many branching plots, and different branches can proceed at the same time. Therefore, the game can be described by plots and plot endpoints, and some plots can only continue after certain specific plot endpoints are reached. To experience the game's completeness, Xiao Dai decides to see all the branches — complete all tasks. But will this delay Xiao Dai's precious sleep time? So please solve this problem.

Input Format

Xiao Dai will give you a list describing the plot flow and completion conditions.

  • The first line contains a number nn, meaning there are nn plot endpoints in total.
  • The second line contains a number mm, meaning there are mm different plots.
  • Each of the next mm lines contains three numbers, meaning that from plot endpoint ii, you must complete a plot that takes time kk in order to reach plot endpoint jj.

Output Format

You must tell Xiao Dai the minimum time needed to complete the entire game, and all possible plot endpoints that will be passed through (output in ascending order).

4
5
1 2 2
2 3 2
3 5 3
1 4 3
4 5 3

7
1 2 3 5

Hint

Constraints

For all testdata, 0<n<1000<n<100, 0<m1200<m\le 120, 0<i1000<i\le 100, 0<j1000<j\le 100, 0<k10000<k\le 1000.

Translated by ChatGPT 5