(最短路 弗洛伊德) Til the Cows Come Home -- POJ --2387
- #include <iostream>
- #include <cstdlib>
- #include <cstring>
- #include <cstdio>
- #include <algorithm>
- #include <vector>
- #include <queue>
- using namespace std;
- #define INF 0xfffffff
- #define N 1002
- int n, m, G[N][N], vis[N], dist[N];
- void IN()
- {
- memset(vis, 0, sizeof(vis));
- for(int i=1; i<=n; i++)
- {
- dist[i]=INF;
- for(int j=1; j<=i; j++)
- {
- G[i][j]=G[j][i]=INF;
- }
- }
- }
- void DIST(int S, int E)
- {
- dist[S]=0;
- for(int i=1; i<=n; i++)
- {
- int index=1, MIN=INF;
- for(int j=1; j<=n; j++)
- {
- if(vis[j]==0 && dist[j]<MIN)
- MIN=dist[j], index=j;
- }
- vis[index]=1;
- for(int j=1; j<=n; j++)
- {
- if(vis[j]==0 && G[index][j]+dist[index]<dist[j])
- {
- dist[j]=G[index][j]+dist[index];
- }
- }
- }
- cout << dist[E] << endl;
- }
- int main()
- {
- while(scanf("%d%d", &m, &n)!=EOF)
- {
- int i, a, b, c;
- IN();
- for(i=0; i<m; i++)
- {
- scanf("%d%d%d", &a, &b, &c);
- G[a][b]=G[b][a]=min(G[a][b], c);
- }
- DIST(1, n);
- }
- return 0;
- }
(最短路 弗洛伊德) Til the Cows Come Home -- POJ --2387的更多相关文章
- Til the Cows Come Home(poj 2387 Dijkstra算法(单源最短路径))
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32824 Accepted: 11098 Description Bes ...
- kuangbin专题专题四 Til the Cows Come Home POJ - 2387
题目链接:https://vjudge.net/problem/POJ-2387 题意:从编号为n的城市到编号为1的城市的最短路. 思路:dijkstra模板题,直接套板子,代码中我会带点注释给初学者 ...
- POJ 2387 Til the Cows Come Home (最短路 dijkstra)
Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Bessi ...
- POJ 2387 Til the Cows Come Home 【最短路SPFA】
Til the Cows Come Home Description Bessie is out in the field and wants to get back to the barn to g ...
- POj2387——Til the Cows Come Home——————【最短路】
A - Til the Cows Come Home Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & ...
- POJ2387 Til the Cows Come Home (最短路 dijkstra)
AC代码 POJ2387 Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to ...
- Til the Cows Come Home 最短路Dijkstra+bellman(普通+优化)
Til the Cows Come Home 最短路Dijkstra+bellman(普通+优化) 贝西在田里,想在农夫约翰叫醒她早上挤奶之前回到谷仓尽可能多地睡一觉.贝西需要她的美梦,所以她想尽快回 ...
- POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)
传送门 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 46727 Acce ...
- Til the Cows Come Home(最短路)
Til the Cows Come Home Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
随机推荐
- 11. 标准库浏览 – Part II
第二部分包含了支持专业编程工作所需的更高级的模块,这些模块很少出现在小脚本中. 11.1. 输出格式 reprlib 模块为大型的或深度嵌套的容器缩写显示提供了 :repr() 函数的一个定制版本: ...
- PAT 1014 福尔摩斯的约会 (20)(代码+思路)
1014 福尔摩斯的约会 (20)(20 分) 大侦探福尔摩斯接到一张奇怪的字条:"我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfd ...
- Android.Study.Question
1. NullPointerException 1.1 发生该异常的原因. 1.2 解决方法有哪几种? try-catch 2. Eclipse 中 debug/run 两个模式,run 是relea ...
- oracle主键修改&设置某一字段可以为null
1.oracle主键修改 1.1)首先查看需要修改的表的主键名,默认的情况下,数据库会自动分配 select * from user_cons_columns where table_name='表名 ...
- java.lang.NoClassDefFoundError: org/apache/ibatis/cursor/Cursor
因为mybatis的版本和mybatis-spring的版本不兼容导致的,解决方法:mybatis的3.4.0及以上版本用mybatis-spring1.3.0及以上版本:mybatis的3.4.0以 ...
- ubuntu12.04下Qt调试器的使用
最近,我一直在用Qt编写C++程序,但在编写过程中遇到了问题,想用Qt Creator中的调试器调试一下,但调试时(在Qt Creator中已配置好相应的调试器)出现“ ptrace:Operatio ...
- python——简单爬虫
因为要学习python,所以看到一些网站有很多文章. 如:http://python.jobbole.com/all-posts/ 目标: 将某个网站脚本编程->python模块这个分类下所有的 ...
- Python编程笔记(第三篇)【补充】三元运算、文件处理、检测文件编码、递归、斐波那契数列、名称空间、作用域、生成器
一.三元运算 三元运算又称三目运算,是对简单的条件语句的简写,如: 简单条件处理: if 条件成立: val = 1 else: val = 2 改成三元运算 val = 1 if 条件成立 else ...
- clean
启动tomcat 报 Could not delete D:/online/.metadata/.plugins/org.eclipse.wst.server.core/tm
- IOS初级:导航控制器
1.AppDelegate.m老生常谈了,创建window,创建根视图rootViewController - (BOOL)application:(UIApplication *)applicati ...