CF464E.The Classic Problem

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:768MB

AC君温馨提醒

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

题目描述

You are given a weighted undirected graph on nn vertices and mm edges. Find the shortest path from vertex ss to vertex tt or else state that such path doesn't exist.

给你一个包含 nn 个顶点和 mm 条边的带权无向图。求从顶点 ss 到顶点 tt 的最短路径;若不存在这样的路径,则说明其不存在。

输入格式

The first line of the input contains two space-separated integers — nn and mm (1≤n≤1051 \leq n \leq 10^5; 0≤m≤1050 \leq m \leq 10^5).

Next mm lines contain the description of the graph edges. The ii-th line contains three space-separated integers — uiu_i, viv_i, xix_i (1≤ui,vi≤n1 \leq u_i, v_i \leq n; 0≤xi≤1050 \leq x_i \leq 10^5). That means that vertices with numbers uiu_i and viv_i are connected by edge of length 2xi2^{x_i} (2 to the power of xix_i).

The last line contains two space-separated integers — the numbers of vertices ss and tt.

The vertices are numbered from 11 to nn. The graph contains no multiple edges and self-loops.

输入的第一行包含两个用空格分隔的整数——nn 和 mm(1≤n≤1051 \leq n \leq 10^5;0≤m≤1050 \leq m \leq 10^5)。

接下来的 mm 行描述图中的边。第 ii 行包含三个用空格分隔的整数——uiu_i、viv_i、xix_i(1≤ui,vi≤n1 \leq u_i, v_i \leq n;0≤xi≤1050 \leq x_i \leq 10^5)。这表示编号为 uiu_i 和 viv_i 的顶点之间有一条长度为 2xi2^{x_i}(即 22 的 xix_i 次幂)的边。

最后一行包含两个用空格分隔的整数——顶点 ss 和 tt 的编号。

顶点编号从 11 到 nn。图中不含重边和自环。

输出格式

In the first line, print the remainder after dividing the length of the shortest path by 1000 000 0071000\,000\,007 (109+710^9 + 7) if the path exists, and −1-1 if the path doesn't exist.

If the path exists, print in the second line integer kk — the number of vertices in the shortest path from vertex ss to vertex tt; in the third line print kk space-separated integers — the vertices of the shortest path in the visiting order. The first vertex should be vertex ss, the last vertex should be vertex tt. If there are multiple shortest paths, print any of them.

第一行输出最短路径长度对 1000 000 0071000\,000\,007(即 109+710^9 + 7)取模的余数;若最短路径不存在,则输出 −1-1。

若最短路径存在,则第二行输出整数 kk —— 从顶点 ss 到顶点 tt 的最短路径所经过的顶点个数;第三行输出 kk 个用空格分隔的整数 —— 按访问顺序给出该最短路径上的各顶点。其中第一个顶点应为 ss,最后一个顶点应为 tt。若存在多条最短路径,输出任意一条即可。

输入输出样例

  • 输入#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 ss to vertex tt is a sequence v0v_0, ..., vkv_k, such that v0=sv_0 = s, vk=tv_k = t, and for any ii from 0 to k−1k - 1 vertices viv_i and vi+1v_{i+1} are connected by an edge.

The length of the path is the sum of weights of edges between viv_i and vi+1v_{i+1} for all ii from 0 to k−1k - 1.

The shortest path from ss to tt is the path which length is minimum among all possible paths from ss to tt.

从顶点 ss 到顶点 tt 的一条路径是一个序列 v0v_0, ..., vkv_k,满足 v0=sv_0 = s、vk=tv_k = t,且对任意 ii(0≤i≤k−10 \le i \le k - 1),顶点 viv_i 与 vi+1v_{i+1} 由一条边相连。

该路径的长度定义为:对所有 ii(0≤i≤k−10 \le i \le k - 1),边 (vi,vi+1)(v_i, v_{i+1}) 的权重之和。

从 ss 到 tt 的最短路径是指:在所有从 ss 到 tt 的可能路径中,长度最小的那条路径。

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

首页