题目传送门

 /*
最短路: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的更多相关文章

  1. OpenJudge/Poj 1125 Stockbroker Grapevine

    1.链接地址: http://poj.org/problem?id=1125 http://bailian.openjudge.cn/practice/1125 2.题目: Stockbroker G ...

  2. POJ 1125 Stockbroker Grapevine【floyd简单应用】

    链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  3. poj 1125 Stockbroker Grapevine(多源最短)

    id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...

  4. POJ 1125 Stockbroker Grapevine

    Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33141   Accepted: ...

  5. poj 1125 Stockbroker Grapevine dijkstra算法实现最短路径

    点击打开链接 Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23760   Ac ...

  6. poj 1125 Stockbroker Grapevine(最短路 简单 floyd)

    题目:http://poj.org/problem?id=1125 题意:给出一个社交网络,每个人有几个别人可以传播谣言,传播谣言需要时间.问要使得谣言传播的最快,应该从那个人开始传播谣言以及使得所有 ...

  7. POJ 1125 Stockbroker Grapevine 最短路 难度:0

    http://poj.org/problem?id=1125 #include <iostream> #include <cstring> using namespace st ...

  8. POJ 1125 Stockbroker Grapevine(最短路基础题)

    Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spre ...

  9. POJ 1125 Stockbroker Grapevine (Floyd最短路)

    Floyd算法计算每对顶点之间的最短路径的问题 题目中隐含了一个条件是一个人能够同一时候将谣言传递给多个人 题目终于的要求是时间最短.那么就要遍历一遍求出每一个点作为源点时,最长的最短路径长是多少,再 ...

随机推荐

  1. Goldbach's Conjecture

     Goldbach's Conjecture Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  2. 绕过 <?PHP exit('Access Denied'); ?> 限制

    绕过 <?PHP exit('Access Denied'); ?> 限制   <?php $shellcode='PD9waHBpbmZvKCk7Pz4';//   base64_ ...

  3. nginx 反向代理 google

    nginx的反向代理,google一直都是不容易打开的,如果你有一台位于国外的vps或者服务器,就可以轻松解决这个问题,这次的主角是nginx,nginx的反向代理现在已经发展很强大了,很多时候拿他来 ...

  4. 39.递归颠倒栈[ReverseStack]

    [题目] 用递归颠倒一个栈.例如输入栈{1, 2, 3, 4, 5},1在栈顶.颠倒之后的栈为{5, 4, 3, 2, 1},5处在栈顶. [分析] 乍一看到这道题目,第一反应是把栈里的所有元素逐一p ...

  5. iOS 中通过使用Google API获得Google服务

    最近使用了google drive这个云存储,官方指导网址为 https://developers.google.com/drive/ios/ . 官方库代码网址为 http://code.googl ...

  6. Java for LeetCode 148 Sort List

    Sort a linked list in O(n log n) time using constant space complexity. 解题思路: 归并排序.快速排序.堆排序都是O(n log ...

  7. DFS:Red and Black(POJ 1979)

    红与黑 题目大意:一个人在一个矩形的房子里,可以走黑色区域,不可以走红色区域,从某一个点出发,他最多能走到多少个房间? 不多说,DFS深搜即可,水题 注意一下不要把行和列搞错就好了,我就是那样弄错过一 ...

  8. ios学习总结(2) -- UIButton的使用

    原文地址 UIButton的类是一个UIControl子类,它实现了在触摸屏上的按钮.触摸一个按钮拦截事件和动作消息发送到目标对象时,它的挖掘.设定的目标和行动方法都继承自UIControl.这个类提 ...

  9. 解决reload AVD list: cvc-enumeration-valid: Value '360dpi' is not facet-valid with respect to enumeration '[ldpi, mdpi, tvdpi, hdpi, 280dpi, xhdpi, 400dpi, xxhdpi, 560dpi, xxxhdpi]'. It must be a v

    解法: 将 D:\work\android-sdk-windows\tools\lib\devices.xml 替换到 D:\work\android-sdk-windows\system-image ...

  10. 谈谈异步加载JavaScript

    前言 关于JavaScript脚本加载的问题,相信大家碰到很多.主要在几个点—— 1> 同步脚本和异步脚本带来的文件加载.文件依赖及执行顺序问题 2> 同步脚本和异步脚本带来的性能优化问题 ...