CF464E.The Classic Problem
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:768MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a weighted undirected graph on n vertices and m edges. Find the shortest path from vertex s to vertex t or else state that such path doesn't exist.
给你一个包含 n 个顶点和 m 条边的带权无向图。求从顶点 s 到顶点 t 的最短路径;若不存在这样的路径,则说明其不存在。
输入格式
The first line of the input contains two space-separated integers — n and m (1≤n≤105; 0≤m≤105).
Next m lines contain the description of the graph edges. The i-th line contains three space-separated integers — ui, vi, xi (1≤ui,vi≤n; 0≤xi≤105). That means that vertices with numbers ui and vi are connected by edge of length 2xi (2 to the power of xi).
The last line contains two space-separated integers — the numbers of vertices s and t.
The vertices are numbered from 1 to n. The graph contains no multiple edges and self-loops.
输入的第一行包含两个用空格分隔的整数——n 和 m(1≤n≤105;0≤m≤105)。
接下来的 m 行描述图中的边。第 i 行包含三个用空格分隔的整数——ui、vi、xi(1≤ui,vi≤n;0≤xi≤105)。这表示编号为 ui 和 vi 的顶点之间有一条长度为 2xi(即 2 的 xi 次幂)的边。
最后一行包含两个用空格分隔的整数——顶点 s 和 t 的编号。
顶点编号从 1 到 n。图中不含重边和自环。
输出格式
In the first line, print the remainder after dividing the length of the shortest path by 1000000007 (109+7) if the path exists, and −1 if the path doesn't exist.
If the path exists, print in the second line integer k — the number of vertices in the shortest path from vertex s to vertex t; in the third line print k space-separated integers — the vertices of the shortest path in the visiting order. The first vertex should be vertex s, the last vertex should be vertex t. If there are multiple shortest paths, print any of them.
第一行输出最短路径长度对 1000000007(即 109+7)取模的余数;若最短路径不存在,则输出 −1。
若最短路径存在,则第二行输出整数 k —— 从顶点 s 到顶点 t 的最短路径所经过的顶点个数;第三行输出 k 个用空格分隔的整数 —— 按访问顺序给出该最短路径上的各顶点。其中第一个顶点应为 s,最后一个顶点应为 t。若存在多条最短路径,输出任意一条即可。
输入输出样例
输入#1
4 4 1 4 2 1 2 0 2 3 0 3 4 0 1 4
输出#1
3 4 1 2 3 4
输入#2
4 3 1 2 4 2 3 5 3 4 6 1 4
输出#2
112 4 1 2 3 4
输入#3
4 2 1 2 0 3 4 1 1 4
输出#3
-1
说明/提示
A path from vertex s to vertex t is a sequence v0, ..., vk, such that v0=s, vk=t, and for any i from 0 to k−1 vertices vi and vi+1 are connected by an edge.
The length of the path is the sum of weights of edges between vi and vi+1 for all i from 0 to k−1.
The shortest path from s to t is the path which length is minimum among all possible paths from s to t.
从顶点 s 到顶点 t 的一条路径是一个序列 v0, ..., vk,满足 v0=s、vk=t,且对任意 i(0≤i≤k−1),顶点 vi 与 vi+1 由一条边相连。
该路径的长度定义为:对所有 i(0≤i≤k−1),边 (vi,vi+1) 的权重之和。
从 s 到 t 的最短路径是指:在所有从 s 到 t 的可能路径中,长度最小的那条路径。
输入解题思路,AI测评打分。不知道怎么写?