# HDU4725 The Shortest Path in Nya Graph（Dijkstra）

## HDU4725 The Shortest Path in Nya Graph（Dijkstra）

Description
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.
Input
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.
Output
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.
Sample Input
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
Sample Output
Case #1: 2
Case #2: 3

## 题意

#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
//#include<unordered_map>
#define lowbit(x) ((x)&-(x));
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e6+10,NN=1e4+10,INF=0x3f3f3f3f,LEN=110;
const ll MOD=1e9+7;
const ull seed=31;
int n,m,c;
struct Edge{
int next,to,dis;
}edge[N];
struct Node{
int id,dis;
Node(int id,int dis):id(id),dis(dis){}
bool friend operator<(const Node &a,const Node &b){
return a.dis>b.dis;
}
};
int num_edge;
edge[num_edge].to=to;
edge[num_edge].dis=dis;
}
int dis[N];
bool done[N];
void dijkstra(){
int s=1;
for(int i=1;i<=2*n;i++){
dis[i]=INF;
done[i]=false;
}
dis[s]=0;
priority_queue<Node>q;
q.push(Node(s,0));
while(!q.empty()){
Node u=q.top();
q.pop();
if(done[u.id]) continue;
done[u.id]=true;
int v=edge[i].to,w=edge[i].dis;
if(done[v]) continue;
if(dis[v]>u.dis+w){
dis[v]=u.dis+w;
q.push(Node(v,dis[v]));
}
}
}
if(dis[n]!=INF) printf("%d\n",dis[n]);
else printf("-1\n");
}
void init(){
num_edge=0;
}
int main(){
int t,T=0;
scanf("%d",&t);
while(t--){
init();
scanf("%d%d%d",&n,&m,&c);
for(int i=1;i<=n;i++){
int l;
scanf("%d",&l);
if(l!=1){
}
}
for(int i=1;i<=m;i++){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
}
printf("Case #%d: ",++T);
dijkstra();
}
}

01-20 1457
05-04 73 09-02 552
09-14 1089
05-04 926
03-11 42
07-25 107
03-30 425
08-08 55
04-11 782