// –Í‹[’n‹æ—\‘I2010 H. Road Construction #include #include #include #include using namespace std; typedef vector< vector< pair > > > graph; class Node{ public: int pos, dist, cost; Node(int pos, int dist, int cost) : pos(pos), dist(dist), cost(cost) {} bool operator < (const Node &nd) const { return make_pair(dist, cost) > make_pair(nd.dist, nd.cost); } }; int main(){ int N, M; static int dist[10000]; static bool visit[10000]; while(cin >> N >> M, N){ graph g(N); for(int i=0;i> u >> v >> d >> c; g[u-1].push_back(make_pair(v-1, make_pair(d, c))); g[v-1].push_back(make_pair(u-1, make_pair(d, c))); } int ans = 0; memset(dist, -1, sizeof(dist)); memset(visit, false, sizeof(visit)); dist[0] = 0; priority_queue qu; qu.push(Node(0, 0, 0)); while(!qu.empty()){ Node nd = qu.top(); qu.pop(); int pos = nd.pos, d = nd.dist; if(dist[pos]!=-1 && dist[pos] < d) continue; if(visit[pos]) continue; visit[pos] = true; ans += nd.cost; for(int i=0;i= dist[pos] + g[pos][i].second.first){ dist[next] = dist[pos] + g[pos][i].second.first; qu.push(Node(next, dist[next], g[pos][i].second.second)); } } } cout << ans << endl; } }