Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
This is a very easy problem, your task is just calculate el camino mas corto en un grafico, and just solo 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 N nodes in total.
You can move from any node in layer x to any node in layer x + 1, with cost C, since the roads are bi-directional, moving from layer x + 1 to layer x is also allowed with the same cost.
Besides, there are M extra edges, each connecting a pair of node u and v, with cost w.
Help us calculate the shortest path from node 1 to node N.
The first line has a number T (T <= 20) , indicating the number of test cases.
For each test case, first line has three numbers N, M (0 <= N, M <= 105) and C(1 <= C <= 103), which is the number of nodes, the number of extra edges and cost of moving between adjacent layers.
The second line has N numbers li (1 <= li <= N), which is the layer of ith node belong to.
Then come N lines each with 3 numbers, u, v (1 <= u, v < =N, u <> v) and w (1 <= w <= 104), which means there is an extra edge, connecting a pair of node u and v, with cost w.
For test case X, output “Case #X: “ first, then output the minimum cost moving from node 1 to node N.
If there are no solutions, output -1.
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
给定一幅有层次的线路图，第一行输入 $N$，$M$，$C$ 表示 $N$ 个几点和 $M$ 条边，每两层之间通过的费用是 $C$。
意思就是，除了走给定的路之外，我们还可以选择穿透层次，花费 $C$ 的费用走到上一层或者下一层的任意一个节点，而不去走题目给定的边。
然后第二行 $N$ 个数就是表示第 $i$ 个节点的层号，然后 $M$ 行是描述边的。
我们可以考虑，怎么样去维护层与层之间的连通，是他们相互通过花费为 $C$ 呢？我们考虑每层新添加两个虚拟节点，一个只出不进，一个只进不出。
由于 spfa 超时了，所以后来改成了迪杰斯特拉。