CF20C.Dijkstra?

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

输入格式

The first line contains two integers nn and mm ( 2<=n<=105,0<=m<=1052<=n<=10^{5},0<=m<=10^{5} ), where nn is the number of vertices and mm is the number of edges. Following mm lines contain one edge each in form aia_{i} , bib_{i} and wiw_{i} ( 1<=ai,bi<=n,1<=wi<=1061<=a_{i},b_{i}<=n,1<=w_{i}<=10^{6} ), where ai,bia_{i},b_{i} are edge endpoints and wiw_{i} is the length of the edge.

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

输出格式

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

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

    输出#1

    1 4 3 5 
  • 输入#2

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

    输出#2

    1 4 3 5 
首页