本文主要是介绍一个人的旅行 hdu 2066,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/***************** Author:fisty* Data:2014-10-19* hdu 2066* 最短路***************/#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAX_N 1111
#define INF 0x3f3f3f3f
int T,S,D;
int map[MAX_N][MAX_N];
int d[MAX_N];
bool used[MAX_N];
int start[MAX_N],end[MAX_N];
int n;int dijkstra(int s){fill(d, d + MAX_N, INF); fill(used, used + MAX_N, false);d[s] = 0;while(true){int v = -1;for(int u = 0;u <= n; u++){if(!used[u] && (v == -1 || d[u] < d[v])) v = u;}if(v == -1)break;used[v] = true;for(int u = 0;u <= n; u++){d[u] = min(d[u] , d[v] + map[v][u]);}}int ans = INF;for(int i = 0;i < D; i++)ans = min(ans, d[end[i]]);return ans;}
int main(){int u,v,t;while(scanf("%d%d%d", &T, &S, &D) != EOF){for(int i = 0;i < 1111;i++){for(int j = 0;j < 1111; j++){map[i][j] = INF;}map[i][i] = 0;}n = 0;for(int i = 0;i < T; i++){scanf("%d%d%d", &u, &v, &t);n = max(max(u, n), v);map[u][v] = map[v][u] = min(map[u][v],t);}for(int i = 0;i < S; i++){ scanf("%d", &start[i]);map[0][start[i]] = map[start[i]][0] = min(map[0][start[i]], 0);}for(int i = D-1;i >= 0; i--){scanf("%d", &end[i]);}int ans = dijkstra(0);printf("%d\n", ans);}return 0;
}
这篇关于一个人的旅行 hdu 2066的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!