CF464E.The Classic Problem

普及/提高-

通过率:0%

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.

输入格式

The first line of the input contains two space-separated integers — nn and mm ( 1<=n<=1051<=n<=10^{5} ; 0<=m<=1050<=m<=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<=u_{i},v_{i}<=n ; 0<=xi<=1050<=x_{i}<=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.

输出格式

In the first line print the remainder after dividing the length of the shortest path by 1000000007 (109+7)1000000007 (10^{9}+7) if the path exists, and -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.

输入输出样例

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

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

首页