Time limit
2s
Memory limit
128 MB
There are n islands and m bridges. Each bridge connects two different islands, and any pair of islands is connected directly by at most one bridge. Bridges may have different strengths, so each bridge has its own limit on how many jewels it can safely carry.
Among the islands, K different islands each contain exactly one jewel. Starting from island 1 with no jewels, you want to collect as many jewels as possible and return to island 1. If you carry too many jewels across a bridge, the bridge collapses, so every bridge crossing must respect that bridge's limit.
You may pass through the same bridge or island multiple times. When you visit an island that contains a jewel, you may choose not to pick it up.
The first line contains n, m, and K.
The next K lines each contain the number of an island that has a jewel.
The next m lines each contain three natural numbers a, b, and c (1 <= c <= 100), describing one bridge. The bridge connects islands a and b, and it can withstand at most c carried jewels. For instance, if c is 2, you may cross that bridge while carrying 0, 1, or 2 jewels. If you try to cross it with 3 or more jewels, the bridge collapses.
Print the maximum number of jewels that can be collected while still returning to island 1.