私信TA
用户名:1564244868
访问量:11590
签 名:
自我简介:
作者: jhrsya 发表时间:2020-02-04 11:54:45 浏览:121 | 评论:0
, greater
> que; fill(dist, dist + V, INF); fill(dist2, dist2 + V, INF); dist[0] = 0; que.push(P(0,0)); while(!que.empty()){ P p = que.top(); que.pop(); int v = p.second, d = p.first; if(dist2[v] < p.first) continue; for(int i = 0; i < G[v].size(); i++){ edge e = G[v][i]; int d2 = d + e.cost; if(dist[e.to] > d2){ //最短路更新 swap(dist[e.to], d2); que.push(P(dist[e.to], e.to)); } if(dist2[e.to] > d2 && dist[e.to] < d2){ //次短路更新 dist2[e.to] = d2; que.push(P(dist2[e.to],e.to)); } } } cout << dist2[V - 1] << endl; } int main(){ cin >> V ; edge m; for(int i = 0; i < V; i++){ for( m.to = 0; m.to < V; m.to++){ cin >> m.cost; if(m.cost == 0) m.cost = INF; G[i].push_back(m); } } dijkstra(); return 0; }
0.0分
2 人评分
看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:
编程语言转换万能编程问答
代码解释器
代码纠错
SQL生成与解释