欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF20C.Dijkstra?
Dijkstra?
CF20C · Dijkstra?
- 难度:1900
- 标签:graphs、shortest paths
- 链接:https://codeforces.com/problemset/problem/20/C
- 时间限制:1 second 内存限制:64 megabytes
- 出现位置:Day08-BFS-最短路-Dijkstra入门-状态图/选做
英文原题面
Statement
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.
Input
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 ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
Output
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 4 3 5
样例 2
输入:
5 6
1 2 2
2 5 5
2 3 4
1 4 1
4 3 3
3 5 1
输出:
1 4 3 5
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |