#P4467. [SCOI2007] k短路

    ID: 3397 远端评测题 2000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串2007四川各省省选排序最短路A*算法

[SCOI2007] k短路

Description

There are nn cities and mm directed roads, with cities numbered from 11 to nn. Each road connects two different cities, and for any two roads, either their starting cities differ or their ending cities differ. Therefore, nn and mm satisfy mn(n1)m \le n(n-1).

Given two cities aa and bb, you can sort all simple paths (each city appears at most once, including the start and end) from aa to bb: first by total length in ascending order, and if lengths are equal, by lexicographical order in ascending order. Your task is to find the kk-th shortest path from aa to bb.

Input Format

The first line contains five positive integers n,m,k,a,bn, m, k, a, b.

Each of the following mm lines contains three integers u,v,lu, v, l, indicating there is a directed road from city uu to city vv with length ll.

Output Format

If there are fewer than kk simple paths from aa to bb, output No. Otherwise, output the kk-th shortest path: starting from city aa, output each visited city in order until city bb, separated by hyphens -.

5 20 10 1 5
1 2 1
1 3 2
1 4 1
1 5 3
2 1 1
2 3 1
2 4 2
2 5 2
3 1 1
3 2 2
3 4 1
3 5 1
4 1 1
4 2 1
4 3 1
4 5 2
5 1 1
5 2 1
5 3 1
5 4 1
1-2-4-3-5
4 6 1 1 4
2 4 2
1 3 2
1 2 1
1 4 3
2 3 1
3 4 1
1-2-3-4
3 3 5 1 3
1 2 1
2 3 1
1 3 1
No

Hint

In the first example, there are 55 cities and all possible roads exist. There are 55 simple paths from city 11 to city 55, sorted as follows:

  • 20% of the testdata: n5n \le 5.
  • 40% of the testdata: n30n \le 30.
  • 100% of the testdata: 2n502 \le n \le 50, 1k2001 \le k \le 200, 1l1041 \le l \le 10^4.

Translated by ChatGPT 5