#BF0000025. Con hẻm (Alley)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Con hẻm (Alley)
Alley
Source: BOJ
Version: Phuoc Hung OJ Extended
Problem Statement
A directed graph has vertices and edges with possibly negative scores . Starting at vertex , you wish to reach vertex , and may traverse vertices and edges multiple times. Print the vertex sequence of a walk attaining the maximum finite total score. If the target is unreachable, or the score can be made arbitrarily large before reaching it, print -1.
Input
The first line contains ; then lines of for directed edges with score .
Output
Print -1 if there is no finite optimum. Otherwise print the vertices on any optimal walk from to , separated by spaces. Multiple valid answers may exist.
Subtasks
-
Subtask 1 (20 points): ; ; .
-
Subtask 2 (30 points): ; ; .
-
Subtask 3 (50 points): ; ; .
Examples
Input
4 4
1 2 2
2 4 2
1 3 1
3 4 2
Output
1 2 4
Explanation
The walk scores , whereas scores ; thus the sample path is optimal.