Max's Anger Contest Series 1 P4 - Greedily Gamboling (Hard Version)

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 2.0s
Memory limit: 1G

Author:
Problem type

To celebrate being able to reconstruct his array, Max has decided to solve Single Source Shortest Path but wants it to be harder, so he came up with the following problem:

Given a graph of N vertices with M bidirectional-weighted edges and K toggles for the bits for any given edge weight you travel, find the shortest path from 1 to N.

The ith toggle allows you to set the pith bit to 0 at most once on any edge weight you travel on from 1 to N.

You can use multiple toggles on the same edge.

What is the minimum cost to travel from 1 to N using at most K of the toggles?

Constraints

1N20000

N1Mmin(50000,N×(N1)2)

0K8

0pi10

1ui,viN

uivi

1wi40000

The data are generated such that there is always a path of edges from 1 to N.

Note the increased constraints on K.

Input Specification

The first line will contain three integers, N, M, and K, the number of vertices, edges, and toggles, respectively.

The next K lines will contain an integer, pi, the ith toggle that can be used to set the pith bit of any edge weight that is travelled on from 1 to N to 0.

The next M lines will contain three integers, ui, vi, and wi, a bidirectional edge from ui to vi with a weight of wi.

Output Specification

Output the minimum distance from 1 to N after using at most K of the toggles.

Sample Input

Copy
3 3 3
1
2
3
1 3 1
1 2 2
2 3 12

Sample Output

Copy
0

Explanation for Sample

It is optimal to take the path 123 to get a distance of 0: use p1=1 on the edge from 1 to 2, giving a weight of 0; use p2=2 on the edge from 2 to 3, giving a weight of 8; use p3=3 on the edge from 2 to 3 again, giving a weight of 0.


Comments

There are no comments at the moment.