Honest Paths

Time limit: 1.25s Memory limit: 256MB Input: Output:

You are given a weighted undirected graph with NN vertices and MM edges. The edges are numbered from 00 to M1M − 1, and edge ii connects vertices xix_i and yiy_i (xiyix_i \neq y_i) with weight wiw_i. There is at most one edge between any pair of vertices.

A path is a sequence of k1k \geq 1 distinct vertices x1,x2,,xkx_1, x_2, \dots , x_k such that there exists an edge between xix_i and xi+1x_{i+1} for all 1i<k1 \leq i \lt k. The length of a path is the sum of the weights of all edges along the path (equal to 00 if the path consists of a single vertex).

It is guaranteed that there exists at least one path between any two vertices of the graph. The distance between two vertices uu and vv, denoted dist(u,v)dist(u, v), is defined as the length of the shortest path connecting them.

An honest path is a path x1,x2,,xkx_1, x_2, \dots , x_k such that dist(xi,xk)>dist(xi+1,xk)dist(x_i, x_k) \gt dist(x_{i+1}, x_k) for all 1i<k1 \leq i \lt k.

Your task is to find the longest honest path that ends at vertex NN.

Input data

The first line contains two integers NN and MM – the number of vertices and the number of edges, respectively.

Each of the next MM lines contains three integers xix_i, yiy_i and wiw_i, describing edge ii.

Output data

Output two lines:

  • The first line should contain two integers LL and KK – the total length of the longest honest path ending at vertex NN, and the number of vertices in that path.
  • The second line should contain KK integers, representing the vertices of one such path in order.

If multiple solutions exist, you may output any of them.

Constraints and clarifications

  • 1N500 0001 \leq N \leq 500\ 000.
  • 1M500 0001 \leq M \leq 500\ 000.
  • 1xi,yiN1 \leq x_i, y_i \leq N for each i=0,1,,M1i = 0, 1, \dots, M − 1.
  • 1wi1 000 000 0001 \leq w_i \leq 1\ 000\ 000\ 000 for each i=0,1,,M1i = 0, 1, \dots, M − 1.
  • The graph is a connected simple graph.
# Score Constraints
1 0 Examples.
2 5 N10N \leq 10.
3 20 N,M2 000N, M \leq 2\ 000.
4 10 The graph is a tree, i.e., M=N1M = N − 1.
5 15 wi=1w_i = 1 for each i=0,1,,M1i = 0, 1, \dots, M − 1.
6 50 No additional constraints.

In this task you can get partial scores in every subtask. You will receive 50%50\% of the points for a subtask if you correctly determine the maximum length, but do not output the path itself.

If you wish to output only the length of the longest honest path, you should output K=0K = 0 on the first line, and omit the second line.

Example 1

stdin

4 4
1 2 1
2 3 1
3 4 1
1 4 2

stdout

2 3
2 3 4

Explanation

In the first sample case an honest path ending in node 44 is 2342 → 3 → 4. We have dist(2,4)=2dist(2, 4) = 2,
dist(3,4)=1dist(3, 4) = 1, dist(4,4)=0dist(4, 4) = 0. Another honest path of maximum length is 141 → 4.

Note that, since dist(1,4)=2dist(1, 4) = 2, the path 12341 → 2 → 3 → 4 is not honest.

Example 2

stdin

4 4
1 2 10
2 3 1
3 4 1
1 4 3

stdout

12 4
1 2 3 4

Log in or sign up to be able to send submissions!