私信TA
用户名:1564244868
访问量:11590
签 名:
自我简介:
作者: jhrsya 发表时间:2020-02-04 10:20:55 浏览:183 | 评论:0
参数, 堆按照first从小到大的顺序取出值 priority_queue
, greater
> que; fill(d, d + V, INF); d[s] = 0; que.push(P(0,s)); while(!que.empty()){ P p = que.top(); que.pop(); int v = p.second; if(d[v] < p.first) continue; for(int i = 0; i < G[v].size(); i++){ edge e = G[v][i]; if(d[e.to] > d[v] + e.cost){ d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } int main(){ int s; cin >> V >> s; 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(s); for(int i = 0; i < V; i++){ if(i == s) continue; cout << (d[i] == INF ? -1 : d[i]) << " "; } return 0; }
0.0分
1 人评分
看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:
编程语言转换万能编程问答
代码解释器
代码纠错
SQL生成与解释