POJ 2387 Til the Cows Come Home
来源:互联网 发布:php 获取视频预览图 编辑:程序博客网 时间:2024/06/05 08:01
http://poj.org/problem?id=2387
使用bellman_ford解决最短路问题。
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;int V,E,num,dis[1010];struct edge{ int from; int to; int v;}node[2010 << 1];void bellman_ford(int scr){ for(int i=1; i<=V; i++) dis[i] = 1e9; dis[scr] = 0; bool flag; for(int i=0; i<V-1; i++){ flag = false; for(int j=1; j<=num; j++){ if(dis[node[j].to] > dis[node[j].from] + node[j].v){ dis[node[j].to] = dis[node[j].from] + node[j].v; flag = true; } } if(!flag) break; }}int main(){// freopen("in.txt", "r", stdin); num = 0; scanf("%d%d",&E,&V); int a,b,c; for(int i=0; i<E; i++){ scanf("%d%d%d",&a,&b,&c); num++; node[num].from = a; node[num].to = b; node[num].v = c; num++; node[num].from = b; node[num].to = a; node[num].v = c; } bellman_ford(V); printf("%d\n",dis[1]); 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
- juce中的ComponentDragger
- 倒排文件索引(Inverted File Index)的建立
- PAT (Advanced) 1014. Waiting in Line (30)
- Navicat for MySQL 9.1.6 Enterprise 注册码:
- sql
- POJ 2387 Til the Cows Come Home
- eCharts使用图表简单示例
- jquery和highcharts折线图、柱形图、饼状图-模拟后台传参源码
- 删除数组中重复元素 (使用stl::set)
- 卡方分布
- 吉大 计算机编程能力培养课程设计 完美的代价
- centos配置静态ip
- C++网络编程之TCP UDP
- plsql 过程化(procedure)sql