#Lutece0835. The Shortest Path in Nya Graph
The Shortest Path in Nya Graph
Migrated from Lutece 835 The Shortest Path in Nya Graph
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
This is a very easy problem, your task is just calculate el camino más corto en un gráfico, and just sólo hay que cambiar un poco el algoritmo. If you do not understand a word of this paragraph, just move on.
The Nya graph is an undirected graph with layers
. Each node in the graph belongs to a layer, there are nodes in total.
You can move from any node in layer to any node in layer , with cost , since the roads are bi-directional, moving from layer to layer is also allowed with the same cost.
Besides, there are extra edges, each connecting a pair of node and , with cost .
Help us calculate the shortest path from node to node .
Input
The first line has a number () , indicating the number of test cases.
For each test case, first line has three numbers , (, ) and (), which is the number of nodes, the number of extra edges and cost of moving between adjacent layers.
The second line has numbers (), which is the layer of node belong to.
Then come lines each with numbers, , (, , ) and (), which means there is an extra edge, connecting a pair of node and , with cost .
Output
For test case , output Case #X:
first, then output the minimum cost moving from node to node .
If there are no solutions, output .
Samples
2
3 3 3
1 3 2
1 2 1
2 3 1
1 3 3
3 3 3
1 3 2
1 2 2
2 3 2
1 3 4
Case #1: 2
Case #2: 3
Resources
2013 ACM-ICPC China Chengdu Provincial Programming Contest