Stockbroker Grapevine POJ 1125 Floyd
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 37069 | Accepted: 20612 |
Description
Unfortunately for you, stockbrokers only trust information coming from their "Trusted sources" This means you have to take into account the structure of their contacts when starting a rumour. It takes a certain amount of time for a specific stockbroker to pass the rumour on to each of his colleagues. Your task will be to write a program that tells you which stockbroker to choose as your starting point for the rumour, as well as the time it will take for the rumour to spread throughout the stockbroker community. This duration is measured as the time needed for the last person to receive the information.
Input
Each person is numbered 1 through to the number of stockbrokers. The time taken to pass the message on will be between 1 and 10 minutes (inclusive), and the number of contacts will range between 0 and one less than the number of stockbrokers. The number of stockbrokers will range from 1 to 100. The input is terminated by a set of stockbrokers containing 0 (zero) people.
Output
It is possible that your program will receive a network of connections that excludes some persons, i.e. some people may be unreachable. If your program detects such a broken network, simply output the message "disjoint". Note that the time taken to pass the message from person A to person B is not necessarily the same as the time taken to pass it from B to A, if such transmission is possible at all.
Sample Input
3
2 2 4 3 5
2 1 2 3 6
2 1 2 2 2
5
3 4 4 2 8 5 3
1 5 8
4 1 6 4 10 2 7 5 2
0
2 2 5 1 5
0
Sample Output
3 2
3 10
Source
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
using namespace std;
typedef long long LL;
#define MAXN 109
#define N 100
#define INF 0x3f3f3f3f
/*
所有点对其他点的最短路径中的最大值 最小的那一点!
*/
int n, k ,Min;
int g[MAXN][MAXN], maxlen[MAXN];
void Floyd()
{
for (int k = ; k <= n; k++)
{
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}
}
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
if (j == i) continue;
maxlen[i] = max(g[i][j], maxlen[i]);
}
if (maxlen[i] < Min)
{
Min = maxlen[i], k = i;
}
}
}
int main()
{
while (scanf("%d", &n), n)
{
memset(g, INF, sizeof(g));
memset(maxlen, -, sizeof(maxlen));
int num,t,d;
for (int i = ; i <= n; i++)
{
scanf("%d", &num);
while (num--)
scanf("%d%d", &t, &d), g[i][t] = d;
}
k = -, Min = INF;
Floyd();
if (Min != INF)
printf("%d %d\n", k, Min);
else
printf("disjoint\n");
}
}
Stockbroker Grapevine POJ 1125 Floyd的更多相关文章
- Stockbroker Grapevine - poj 1125 (Floyd算法)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30454 Accepted: 16659 Description S ...
- poj 1125 (floyd)
http://poj.org/problem?id=1125. 题意:在经纪人的圈子里,他们各自都有自己的消息来源,并且也只相信自己的消息来源,他们之间的信息传输也需要一定的时间.现在有一个消息需要传 ...
- POJ 1125 Stockbroker Grapevine【floyd简单应用】
链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...
- 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
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
- poj 1125 Stockbroker Grapevine(多源最短)
id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...
- POJ 1125:Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64 ...
- POJ 1125 Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33141 Accepted: ...
随机推荐
- [Qt Creator 快速入门] 第0篇 开始学习Qt 与Qt Creator
Qt官方信息 Qt官网:http://qt.digia.com/ Qt开源官网:http://qt-project.org/ Qt最新版本下载:http://qt-project.org/downlo ...
- linux学习之路6 Vi文本编辑器
vim是vi的增强版本 vim拥有三种模式: 命令模式(常规模式) vim启动后,默认进入命令模式.任何模式都可以通过按esc键回到命令模式(可以多按几次.命令模式可以通过键入不同的命令完成选择.复制 ...
- 51nod1298 圆与三角形
1298 圆与三角形 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出圆的圆心和半径,以及三角形的三个顶点,问圆同三 ...
- 02—IOC实现项目中的解耦
- pyinstaller遇到的坑
最近接了一个python的活,具体的就不展开,大概就是需要搭建一个服务器,接收客户端上传文件,调用算法模型,然后返回相应的数据.算法模块用的是tensorflow模块,里面一大堆东西,网上看了很多,最 ...
- Http协议对格式、请求头、方法
######### #概览 ######### 超文本传输协议(Http: Hyper Text Transfer Protocol) :用于发送WWW方式的数据.采用TCP/IP协议,是一个无状态协 ...
- 页面置换算法-LRU(Least Recently Used)c++实现
最近最久未使用(LRU)置换算法 #include <iostream> #include <cstdio> #include <cstring> #include ...
- 在struct 中使用string,赋值会报错
struct中最好使用char来代替string,因为string的大小不是固定的
- interface与抽象类
抽象类: 定义:在 class 前加了 abstract 关键字且存在抽象方法(在类方法 function 关键字前加了 abstract 关键字)的类 抽象类不能被实例化. 抽象类被继承之后,子类必 ...
- Android(java)学习笔记205:JNI之编写jni程序适配所有处理器型号
1. 还是以"02_两个数相加"为例,你会发现这个jni程序只能在ARM处理器下运行,如下: 如果我们让上面的程序运行在x86模拟器上,处理平台不对应,报如下错误: 03-29 ...