PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BF0000025. Con hẻm (Alley)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Con hẻm (Alley)

Alley

Source: BOJ

Version: Phuoc Hung OJ Extended

Problem Statement

A directed graph has nn vertices and mm edges with possibly negative scores ww. Starting at vertex 11, you wish to reach vertex nn, 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 n,mn,m; then mm lines of u,v,wu,v,w for directed edges with score ww.

Output

Print -1 if there is no finite optimum. Otherwise print the vertices on any optimal walk from 11 to nn, separated by spaces. Multiple valid answers may exist.

Subtasks

  • Subtask 1 (20 points): 2≤n≤122\le n\le12; 0≤m≤500\le m\le50; −100≤w≤100-100\le w\le100.

  • Subtask 2 (30 points): 2≤n≤502\le n\le50; 0≤m≤10000\le m\le1000; −1000≤w≤1000-1000\le w\le1000.

  • Subtask 3 (50 points): 2≤n≤1002\le n\le100; 0≤m≤200000\le m\le20000; −1000≤w≤1000-1000\le w\le1000.

Examples

Input

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

Output

1 2 4

Explanation

The walk 1→2→41\to2\to4 scores 44, whereas 1→3→41\to3\to4 scores 33; thus the sample path is optimal.