图论trainning-part-1 G. Stockbroker Grapevine
G. Stockbroker Grapevine
64-bit integer IO format: %lld Java class name: Main
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 解题:Floyd算法,选择一个人,从这个人传递信息到其他的人的最长时间最短。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#define LL long long
#define INF 0x3f3f3f
using namespace std;
int mp[][];
int main() {
int n,i,j,u,v,w,k;
while(scanf("%d",&n),n) {
for(i = ; i <= n; i++)
for(j = ; j <= n; j++)
mp[i][j] = INF;
for(i = ; i <= n; i++) {
scanf("%d",&j);
while(j--) {
scanf("%d%d",&v,&w);
mp[i][v] = w;
}
}
for(k = ; k <= n; k++) {
for(i = ; i <= n; i++) {
for(j = ; j <= n; j++)
if(mp[i][k] < INF && mp[k][j] < INF && mp[i][j] > mp[i][k]+mp[k][j])
mp[i][j] = mp[i][k]+mp[k][j];
}
}
int ans = INF,index,temp;
for(i = ; i <= n; i++) {
temp = ;
for(j = ; j <= n; j++) {
if(i == j) continue;
if(mp[i][j] > temp) temp = mp[i][j];
}
if(temp < ans) {
ans = temp;
index = i;
}
}
printf("%d %d\n",index,ans);
}
return ;
}
图论trainning-part-1 G. Stockbroker Grapevine的更多相关文章
- POJ 1125:Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64 ...
- Stockbroker Grapevine(floyd+暴力枚举)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31264 Accepted: 171 ...
- POJ 1125 Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33141 Accepted: ...
- Stockbroker Grapevine(floyd)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28231 Accepted: ...
- poj 1125 Stockbroker Grapevine dijkstra算法实现最短路径
点击打开链接 Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23760 Ac ...
- 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 ...
- Stockbroker Grapevine(最短路)
poj——1125 Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36112 ...
- Stockbroker Grapevine POJ 1125 Floyd
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37069 Accepted: ...
随机推荐
- Spring注解和JDK注解
1.添加xsd约束 xmlns:context="http://www.springframework.org/schema/context" http://www.springf ...
- 连接sql server、插入数据、从数据库获取时间(C#)
using System; using System.Data.SqlClient; namespace Test { //连接数据库 public class Connection { privat ...
- Windows7环境下Apache连接MySQL提示“连接已重置”的解决办法
win7下手动搭建wamp环境,碰到的几个坑总结下, 1.能正常访问php和html类型文件,但是访问项目文件时老是连接被重置,后来总结是数据库的问题,就写测试用例测试php能否成功调用数据库, &l ...
- iOS之创建CocoaPods公有库教程
简介 在开发过程中,经常会使用到第三框架,我们通过一个pod install命令,很方便的就将第三方框架加到我们自己的项目中. 如果我们也想将自己写的组件或库开源出去,让别人也可以通过pod inst ...
- 使用 PHPUnit 和 Selenium 进行测试
适用于 PHP 的 NetBeans IDE 支持 PHPUnit 自动测试.通过 PHPUnit,NetBeans IDE 可为 PHP 提供代码覆盖率,这与 IDE 为 Python 提供的代码覆 ...
- 洛谷 P1363 幻想迷宫
题目描述 背景 Background (喵星人LHX和WD同心协力击退了汪星人的入侵,不幸的是,汪星人撤退之前给它们制造了一片幻象迷宫.) WD:呜呜,肿么办啊…… LHX:momo...我们一定能走 ...
- 使用office 365打开excel文件报错,提示“向程序发送命令时出现问题”
我买了一套正版的office 365装在我的windows10 上.但是每次打开excel都会报错,如图一.求教了微软技术人员,他们给出了以下办法: 图一 方法一: 修复安装Office ====== ...
- 基于Vmware player的Windows 10 IoT core + RaspberryPi2安装部署
本文记录了基于Vmware Player安装Windows10和VS2015开发平台的过程,以及如何在RaspberryPi2.0上启动Windows10 IoT core系统,并通过一个简单的hel ...
- 如何用JavaScript判断前端应用运行环境(移动平台还是桌面环境)
我们部署在某些云平台或者Web服务器上的前端应用,既可以用PC端浏览器访问,也可以用手机上的浏览器访问. 在前端应用里,有时候我们需要根据运行环境的不同做出对应处理.比如下面这段逻辑,如果判断出应用当 ...
- UVA 1349 Optimal Bus Route Design (二分图最小权完美匹配)
恰好属于一个圈,那等价与每个点有唯一的前驱和后继,这让人想到了二分图, 把一个点拆开,点的前驱作为S集和点的后继作为T集,然后连边,跑二分图最小权完美匹配. 写的费用流..最大权完美匹配KM算法没看懂 ...