题目:http://acm.hdu.edu.cn/showproblem.php?pid=1874
#include<bits/stdc++.h>
#define PI 3.1415926
#define INF 1e18
#define min(a,b) a<b?a:b
#define max(a,b) a>b?a:b
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
const int _max = 250;
bool v[_max];
ll M[_max][_max];
ll dis[_max];
ll n,m;
ll s,e;
void Dijsktra(){
for(int i = 0 ; i < n ; i++) dis[i] = M[s][i];
v[s]=false;
dis[s]=0;
for(int i = 0 ; i < n ; i++){
int x = s;
m = INF;
for(int j = 0 ; j < n ; j++)
if(v[j] && dis[j] <= m)
m = dis[x=j];
v[x]=false;
for(int j = 0; j < n ; j++)
dis[j] = min(dis[j],dis[x]+M[x][j]);
}
}
int main(){
while(cin>>n>>m){
int a,b,p;
memset(v,true,sizeof(v));
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < n ; j++)
if(i==j) dis[i] = 0;
else M[i][j] = INF;
for(int i = 0 ; i < m ; i++){
cin>>a>>b>>p;
if(p<M[a][b]){
M[a][b] = p;
M[b][a] = p;
}
}
cin>>s>>e;
for(int i = 0 ; i < n ; i++)
dis[i] = INF;
Dijsktra();
if (dis[e] == INF) cout << -1 << endl;
else cout << dis[e] << endl;
}
return 0;
}