#d1104. no crossing
no crossing
No Crossing
Problem Description
Given a directed graph, find the shortest path that passes through exactly nodes, with the requirement that each chosen edge must not "cross" any previously visited node. That is, for an edge on the path, there must be no previously visited node such that .
Input Format
The first line contains three integers .
The next lines each contain three integers , indicating a directed edge from of length .
Output Format
One integer — the answer. If no path satisfies the condition, output .
Sample Input 1
7 4 4
1 6 2
6 2 2
2 4 2
2 7 1
Sample Output 1
6
Sample Input 2
4 3 4
2 1 2
1 3 2
3 4 2
4 1 1
Sample Output 2
3
Sample Explanation
In sample 1, the shortest path is . The path is invalid because .
Constraints
All data satisfy , , , .