[POJ-2387]Til the Cows Come Home
来源:互联网 发布:淘宝网瘦身腰带 编辑:程序博客网 时间:2024/06/05 05:38
从V到1可以,从1到V会WA,原因分析中
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<vector>#include<queue>#include<algorithm>using namespace std;const int MAX_V = 1000 + 5;const int INF = 0xffffff;struct edge{ int to, cost; edge(int tt, int cc):to(tt), cost(cc) { }};typedef pair<int, int> P;int V;vector<edge> G[MAX_V];int d[MAX_V];void dijkstra( int s ) { priority_queue< P, vector<P>, greater<P> > 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 T, N; while( cin >> T >> V ) { while(T--) { int a, b, c; cin >> a >> b >> c; G[a].push_back( edge(b,c) ); G[b].push_back( edge(a,c) ); } dijkstra( V ); cout << d[1] << endl; } return 0;}
阅读全文
0 0
- POJ 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- Poj 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ-2387-Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- 用bbed修改数据文件头,跳过丢失的归档
- 循环神经网络(Recurrent Neural Network)
- 微信小程序----导航栏透明渐变二
- Android动画解析(二)-----属性动画
- golang语言中map的初始化及使用
- [POJ-2387]Til the Cows Come Home
- 33. Search in Rotated Sorted Array
- SQL AND & OR (运算符)
- 按住鼠标左键直接拖动页面,横向滚动
- spring mvc 拦截器
- angular项目的启动流程
- 【章节3】MySQL数据类型、数据表设计
- telnetd源代码分析之输入一个字符的四个阶段
- CAD转图片怎么设置输出格式