#P15703. [2018 KAIST RUN Spring] Xtreme NP-hard Problem?!

[2018 KAIST RUN Spring] Xtreme NP-hard Problem?!

题目描述

Caution! This problem turned out to be NP-hard. But since there was no rules against writing a NP-hard problem, we decided to leave this problem here.

There is a bidirectional graph consisting of nn vertices and mm edges. The vertices and edges are numbered from 1 to nn and 1 to mm respectively, and the weight of edge ii is wiw_i. (1im1 \le i \le m) Given a natural number kk, find the length of the shortest simple path that starts from vertex 1 and ends at vertex nn, and consists of kk edges. A simple path is a path that does not visit same vertex twice, and length of a path is the sum of weight of edges that consists the path.

输入格式

In the first line, three space-separated integers nn, mm, kk are given.

In the next mm lines, three space-separated integers xix_i, yiy_i, wiw_i are given. They denote that edge ii is connecting vertex xix_i and vertex yiy_i, and has weight wiw_i.

No loops or multiple edges are given.

输出格式

Print the length of the shortest simple path that starts from vertex 1 and ends at vertex nn, and consists of kk edges. If there is no such path, print 1-1.

6 6 3
1 2 3
2 3 1
3 6 4
1 4 1
4 5 5
5 6 9
8

提示

Constraints

  • 2n<1062 \le n < 10^6
  • 1m,k<1061 \le m, k < 10^6
  • 1xi,yin1 \le x_i, y_i \le n
  • xiyix_i \ne y_i (1in1 \le i \le n)
  • ij{xi,yi}{xj,yj}i \ne j \Rightarrow \{x_i, y_i\} \ne \{x_j, y_j\} (1i,jn1 \le i, j \le n)
  • 1wi1081 \le w_i \le 10^8
  • min(n,m,k)5\min(n,m,k)\le 5