为了检验模板正确性写的水题
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
using namespace std;
#define INF 1e9
#define maxn 110
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define mset(x) memset(x,0,sizeof(x))
int n, s, e, m, k;
struct edgenode{
int from, to, dist;
edgenode(){}
edgenode(int u, int v, int w): from(u), to(v), dist(w){}
};
struct heapnode{
int d, u;
bool operator<(const heapnode& rhs)const{
return d>rhs.d;
}
heapnode(){};
heapnode(int d, int u): d(d), u(u){}
};
vector<edgenode> edges;
vector<int> G[maxn];
bool done[maxn];
int d[maxn];
void AddEdge(int from, int to, int dist){
edges.push_back(edgenode(from, to, dist));
G[from].push_back(edges.size()-1);
}
void dij(int s){
priority_queue<heapnode> Q;
rep(i,0,n) d[i] = INF;
d[s] = 0;
mset(done);
Q.push(heapnode(0, s));
while(!Q.empty()){
heapnode x = Q.top(); Q.pop();
int u = x.u;
if(done[u]) continue;
done[u] = true;
for(int i=0; i<G[u].size(); i++){
edgenode& e = edges[G[u][i]];
if(d[e.to] > d[u] + e.dist){
d[e.to] = d[u] + e.dist;
Q.push(heapnode(d[e.to], e.to));
}
}
}
}
void init(){
rep(i,0,n) G[i].clear();
edges.clear();
}
int main(){
int kase = 0;
while(cin>>n>>m, n, m){
init();
int x, y, z;
rep(i,1,m){
scanf("%d%d%d",&x, &y, &z);
AddEdge(x, y, z);
AddEdge(y, x, z);
}
dij(1);
printf("%d\n", d[n]);
}
return 0;
}