logo AlgoBeat OnlineJudge
登录 注册

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

内存限制:1024 MiB 时间限制:5000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 vertices and edges. The vertices and edges are numbered from 1 to and 1 to respectively, and the weight of edge is . () Given a natural number , find the length of the shortest simple path that starts from vertex 1 and ends at vertex , and consists of 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 , , are given.

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

No loops or multiple edges are given.

输出格式

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

样例

样例输入 1

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

样例输出 1

8

数据范围与提示

Constraints

  • ()
  • ()