POJ 2387 Til the Cows Come Home
来源:互联网 发布:淘宝网高腰半身a字裙 编辑:程序博客网 时间:2024/05/22 21:35
题目大意:
题目链接
注释代码:
无注释代码:
#include <iostream>#include <cstdio>#include <queue>#defineINF1000000#defineMAXN1000#defineMAXM4000using namespace std;structArc {intv;intc;Arc(void) {}Arc(int vv, int cc) : v(vv), c(cc) {}};structNode {intu;intd;Node(void) {}Node(int uu, int dd) : u(uu), d(dd) {}booloperator<(const Node &oth)const {return d > oth.d;}};Arcarc[MAXM + 1];inthead[MAXN + 1];intnxt[MAXM + 1];inte;intdis[MAXN + 1];boolvis[MAXN + 1];priority_queue<Node>heap;voidaddarc( int u, int v, int c ) {arc[e].v = v;arc[e].c = c;nxt[e] = head[u];head[u] = e++;}intdij(int n) {intu, v;inti;Nodenode;for ( i = 1; i <= n; i++ ) dis[i] = INF;heap.push(Node(1, 0));dis[1] = 0;while (true) {node = heap.top();heap.pop();if ( ( u = node.u ) == n ) return dis[n];if ( vis[u] ) continue;vis[u] = true;for ( i = head[u]; i; i = nxt[i] )if ( !vis[ v = arc[i].v ] && dis[u] + arc[i].c < dis[v] ) {dis[v] = dis[u] + arc[i].c;heap.push(Node(v, dis[v]));}}return -1;}intmain() {intn, m;intu, v, c;e = 1;scanf("%d%d", &m, &n);while ( m-- ) {scanf("%d%d%d", &u, &v, &c);addarc( u, v, c );addarc( v, u, c );}printf("%d\n", dij(n));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
- 作业调度算法
- Fedora11下找回/dev/dsp设备
- 使用Input Text with LOV 实现显示名称保存ID
- JS函数定义方式的区别
- 图片格式及内存占用
- POJ 2387 Til the Cows Come Home
- 使用Input Text with LOV + Transient Attribute 实现显示名称保存ID
- 黑马程序员----IOS笔记 #pragma mark的用法
- POJ3525-Most Distant Point from the Sea(二分+半平面交)
- 使用Choice List 实现查询
- Libgdx的使用(16)——内存管理和对象池
- Linux bash shell 逐行读取文件的三种方法
- 元数据驱动
- [小技巧] 快速给目录打包