poj 2387 Til the Cows Come Home
来源:互联网 发布:软件产品设计文档模板 编辑:程序博客网 时间:2024/05/31 06:24
最基本的最短路问题
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int INF = 0x3f3f3f3f;int edge[2005][2005];int main(){ int n, k; cin >> k >> n; int v, u, dis; for (int i = 0; i != n; ++i) for (int j = 0; j != n; ++j) edge[i][j] = INF; for (int i = 0; i != k; ++i) // 无向图 建立双向边 { scanf("%d%d%d",&v,&u,&dis); if (edge[v-1][u-1] >= dis) edge[v-1][u-1] = dis; if (edge[u-1][v-1] >= dis) edge[u-1][v-1] = dis; } int vis[2005],d[2005]; memset(d,0,sizeof(d)); memset(vis,0,sizeof(vis)); for (int i = 1; i != n; ++i) d[i] = INF; for (int i = 0; i != n; ++i) { int point; int minn = INF; for (int j = 0; j != n; ++j) if (!vis[j] && d[j] < minn) { minn = d[j]; point = j; } vis[point] = 1; for (int j = 0; j != n; ++j) if (!vis[j]) d[j] = min(d[j],d[point] + edge[point][j]); //*松弛 } cout << d[n-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
- 红黑二叉查找树
- gerrit H2 数据库管理
- 剑指offer刷题之java实现的二叉搜索树的后序遍历序列
- 提取最长转录本的代码
- 一步一步在ubuntu上安装即时通讯服务器-Openfire
- poj 2387 Til the Cows Come Home
- 重复子串问题(五):求最长回文字符子串
- 动态规划专题之zoj1013
- B. Berland National Library
- 浅析CVE-2015-3636
- Ubuntu 安装mysql和简单操作
- CS224d Problem set 2作业
- 如何实时查看linux下的日志
- uva 673 Parentheses Balance