第 20 场 Codeforces Alpha Round(Codeforces 赛制)
C
Dijkstra?
Dijkstra?
Codeforces
1900
原题
← B→

Dijkstra?AI (CI翻译)

You are given a weighted undirected graph. The vertices are enumerated from 1 to $*n*$. Your task is to find the shortest path between the vertex $1$ and the vertex $*n*$.

你得到了一张带权无向图。顶点编号从 1 到 $*n*$。你的任务是求顶点 1 与顶点 $*n*$ 之间的最短路径。AI (CI翻译)

Input

输入格式

AI (CI翻译)

The first line contains two integers $*n*$ and $*m*$ ($2 ≤ *n* ≤ 10^{5}, 0 ≤ *m* ≤ 10^{5}$), where $*n*$ is the number of vertices and $*m*$ is the number of edges. Following $*m*$ lines contain one edge each in form $*a*_{*i*}$, $*b*_{*i*}$ and $*w*_{*i*}$ ($1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*, 1 ≤ *w*_{*i*} ≤ 10^{6}$), where $*a*_{*i*}, *b*_{*i*}$ are edge endpoints and $*w*_{*i*}$ is the length of the edge.

第一行包含两个整数 $*n*$ 和 $*m*$($2 ≤ *n* ≤ 10^{5}, 0 ≤ *m* ≤ 10^{5}$),其中 $*n*$ 是顶点数,$*m*$ 是边数。接下来的 $*m*$ 行每行描述一条边,格式为 $*a*_{*i*}$、$*b*_{*i*}$ 和 $*w*_{*i*}$($1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*, 1 ≤ *w*_{*i*} ≤ 10^{6}$),其中 $*a*_{*i*}$、$*b*_{*i*}$ 是边的两个端点,$*w*_{*i*}$ 是边的长度。AI (CI翻译)

It is possible that the graph has loops and multiple edges between pair of vertices.

图中可能存在自环,以及同一对顶点之间的重边。AI (CI翻译)

Output

输出格式

AI (CI翻译)

Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.

如果不存在路径,只输出整数 -1。否则,输出最短路径。如果有多种答案,输出其中任意一种。AI (CI翻译)

样例

Input #1
5 6
1 2 2
2 5 5
2 3 4
1 4 1
4 3 3
3 5 1
Output #1
1 4 3 5
InputCopy OutputCopy
Input #2
5 6
1 2 2
2 5 5
2 3 4
1 4 1
4 3 3
3 5 1
Output #2
1 4 3 5
InputCopy OutputCopy
题目信息
题号
20C
时间限制
1 s
内存限制
64 MB
标签
图论
最短路

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。