CF20C.Dijkstra?

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:64MB

AC君温馨提醒

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

题目描述

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.

给你一个带权无向图。顶点编号从 11 到 nn。你的任务是求出顶点 11 与顶点 nn 之间的最短路径。

输入格式

The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), 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 ≤ 106), where a__i, b__i are edge endpoints and w__i is the length of the edge.

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

第一行包含两个整数 nn 和 mm(2≤n≤1052 \leq n \leq 10^5,0≤m≤1050 \leq m \leq 10^5),其中 nn 表示顶点数,mm 表示边数。接下来的 mm 行每行描述一条边,格式为 aia_i, bib_i 和 wiw_i(1≤ai,bi≤n1 \leq a_i, b_i \leq n,1≤wi≤1061 \leq w_i \leq 10^6),其中 aia_i、bib_i 是该边的两个端点,wiw_i 是该边的长度。

图中可能存在自环以及任意一对顶点之间的多条边。

输出格式

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-1;否则输出最短路径。若存在多个解,输出其中任意一个即可。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页