最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
/*
最短路:Floyd模板题
主要是两点最短的距离和起始位置
http://blog.csdn.net/y990041769/article/details/37955253
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
using namespace std; const int MAXN = + ;
const int INF = 0x3f3f3f3f;
int d[MAXN][MAXN]; void Floyd_Warshall(int n)
{
for (int k=; k<=n; ++k)
{
for (int i=; i<=n; ++i)
{
for (int j=; j<=n; ++j)
{
if (d[i][j] > d[i][k] + d[k][j])
d[i][j] = d[i][k] + d[k][j];
}
}
}
} void work(int n)
{
Floyd_Warshall (n);
int res; int ans = INF; int num;
for (int i=; i<=n; ++i)
{
res = ;
for (int j=; j<=n; ++j)
{
if (i == j) continue;
if (res < d[i][j]) res = d[i][j];
}
if (ans > res)
{
ans = res;
num = i;
}
} printf ("%d %d\n", num, ans);
} int main(void) //POJ 1125 Stockbroker Grapevine
{
//freopen ("E.in", "r", stdin); int n, m;
while (~scanf ("%d", &n) && n)
{
for (int i=; i<=n; ++i)
for (int j=; j<=n; ++j) d[i][j] = INF;
for (int i=; i<=n; ++i)
{
scanf ("%d", &m);
int x, y;
for (int j=; j<=m; ++j)
{
scanf ("%d%d", &x, &y);
d[i][x] = y;
}
} work (n);
} return ;
}
最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine的更多相关文章
- OpenJudge/Poj 1125 Stockbroker Grapevine
1.链接地址: http://poj.org/problem?id=1125 http://bailian.openjudge.cn/practice/1125 2.题目: Stockbroker G ...
- POJ 1125 Stockbroker Grapevine【floyd简单应用】
链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- poj 1125 Stockbroker Grapevine(多源最短)
id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...
- POJ 1125 Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33141 Accepted: ...
- poj 1125 Stockbroker Grapevine dijkstra算法实现最短路径
点击打开链接 Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23760 Ac ...
- poj 1125 Stockbroker Grapevine(最短路 简单 floyd)
题目:http://poj.org/problem?id=1125 题意:给出一个社交网络,每个人有几个别人可以传播谣言,传播谣言需要时间.问要使得谣言传播的最快,应该从那个人开始传播谣言以及使得所有 ...
- POJ 1125 Stockbroker Grapevine 最短路 难度:0
http://poj.org/problem?id=1125 #include <iostream> #include <cstring> using namespace st ...
- POJ 1125 Stockbroker Grapevine(最短路基础题)
Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spre ...
- POJ 1125 Stockbroker Grapevine (Floyd最短路)
Floyd算法计算每对顶点之间的最短路径的问题 题目中隐含了一个条件是一个人能够同一时候将谣言传递给多个人 题目终于的要求是时间最短.那么就要遍历一遍求出每一个点作为源点时,最长的最短路径长是多少,再 ...
随机推荐
- JavaScript中的Function(函数)对象详解
JavaScript中的Function对象是函数,函数的用途分为3类: 作为普通逻辑代码容器: 作为对象方法: 作为构造函数. 1.作为普通逻辑代码容器 function multiply(x, y ...
- Seventh scrum meeting - 2015/11/1
新的一月开始了!今天是周末,所以大家的开发进度有点减慢,享受一个愉快的周末~ 今天大家的开发都没有遇到什么问题,因为这几天下来,大家对android的开发流程都比较熟悉了,暂时不会遇到新的问题了. 我 ...
- redis和memcached比较
1.Memcached采用客户端-服务器的架构,服务器维护了一个键-值关系的数据表,服务器之间相互独立,互相之间不共享数据也不做任何通讯操作.客户端需要知道所有的服务器,并自行负责管理数据在各个服务器 ...
- Linux内核之数据双链表
导读 Linux 内核中自己实现了双向链表,可以在 include/linux/list.h 找到定义.我们将会首先从双向链表数据结构开始介绍内核里的数据结构.为什么?因为它在内核里使用的很广泛,你只 ...
- NGUI 新版操作教程
http://www.tasharen.com/forum/index.php?topic=6754
- http://backboneconf.com/ @前端 真好
http://backboneconf.com/ @前端http://backboneconf.com/ @前端http://backboneconf.com/ @前端http://backbonec ...
- 硬盘安装ubuntu注意事项
按照教程 http://teliute.org/linux/Ubsetup/jichu3/jichu3.html 安装64位ubuntu的时候,因为64位版本的iso安装包里没有vmlinuz文件,而 ...
- Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. Example Given 1-> ...
- iOS viewDidAppear 和 viewWillAppear
今天发现,如果用navigation push一个controller,那么从动画开始就调用viewwillappear,动画全部停止才会调用viewDidAppear,不知道是否正确,先做记录,带验 ...
- zpf 视图
2014年8月19日 18:12:16 smarty使用了2年, 使用PHP本身做模版引擎也有4个多月了, 最终还是在我的这个框架中抛弃了smarty,转用原生的PHP代码做模版引擎,并简单写了一个视 ...