PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000401. Đường đi có trung bình nhỏ nhất (Minimum Average Path)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đường đi có trung bình nhỏ nhất (Minimum Average Path)

Minimum Average Path

Version: Phuoc Hung OJ Extended

PHOJ practice edition. Its constraints, input/output format, examples and judging rules are specified below.

Problem Statement

Given a directed acyclic graph (DAG) with nn vertices and mm integer-weighted edges, find a path from vertex 1 to vertex nn minimizing the arithmetic mean of its edge weights. At least one such path exists. Any optimal path is accepted.

Input

The first line contains n,mn,m. Each of the next mm lines contains u,v,wu,v,w, denoting a directed edge from uu to vv of weight ww. No ordered pair (u,v)(u,v) is repeated. Vertex labels need not be in topological order.

Output

Print the number of edges qq on the first line. On the second line print q+1q+1 vertex labels in path order, starting at 1 and ending at nn. The mean must be exactly optimal; no floating-point tolerance is used.

Subtasks

  • Subtask 1 (20 points): 2≤n≤122\le n\le 12; 1≤m≤min⁡(66,n(n−1)/2)1\le m\le\min(66,n(n-1)/2); 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; 0≤w≤1000\le w\le100; the graph is a simple DAG with a path from 1 to nn.
  • Subtask 2 (30 points): 2≤n≤2502\le n\le 250; 1≤m≤min⁡(10000,n(n−1)/2)1\le m\le\min(10000,n(n-1)/2); 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; 0≤w≤1000\le w\le100; the graph is a simple DAG with a path from 1 to nn.
  • Subtask 3 (50 points): 2≤n≤100002\le n\le 10000; 1≤m≤min⁡(50000,n(n−1)/2)1\le m\le\min(50000,n(n-1)/2); 1≤u,v≤n1\le u,v\le n, u≠vu\ne v; 0≤w≤1000\le w\le100; the graph is a simple DAG with a path from 1 to nn.

Created examples

Input

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

Output

2
1 3 4

Explanation

There are exactly two paths from 1 to 4: through 2, with mean (10+2)/2=6(10+2)/2=6, and through 3, with mean (4+4)/2=4(4+4)/2=4. Choose the second path, which has 2 edges and vertices 1, 3, 4.

Input

3 3
1 2 5
2 3 5
1 3 5

Output

1
1 3

Explanation

The direct path 1→31\to3 has mean 5. The path 1→2→31\to2\to3 has mean (5+5)/2=5(5+5)/2=5. Both are optimal; the sample chooses the direct path with one edge.

Input

5 4
1 4 0
4 2 0
2 5 1
1 5 1

Output

3
1 4 2 5

Explanation

The path 1→4→2→51\to4\to2\to5 has 3 edges of total weight 0+0+1=10+0+1=1, so its mean is 1/31/3. The direct path 1→51\to5 has mean 1. There are no other paths from 1 to 5, so the three-edge path is optimal.