#P6822. [PA 2012 Finals] Tax

[PA 2012 Finals] Tax

Description

Given an undirected graph with nn vertices and mm edges, the cost of passing through a vertex is the larger of the weights of the two edges used to enter and leave this vertex. Find the minimum total cost from the start vertex 11 to vertex nn. The cost at the start vertex is the weight of the edge leaving the start vertex, and the cost at the end vertex is the weight of the edge entering the end vertex.

Input Format

The first line contains two integers n,mn,m, representing the number of vertices and the number of edges.

The next mm lines each contain three integers a,b,ca,b,c, meaning there is an edge of length cc between aa and bb.

Output Format

Output one integer on a single line, representing the answer.

4 5
1 2 5
1 3 2
2 3 1
2 4 4
3 4 8
12

Hint

Constraints: 1n1051\leq n\leq 10^51m2×1051\leq m\leq 2\times 10^51c1061\leq c\leq 10^6

Translated by ChatGPT 5