图论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: ...
随机推荐
- arcengine 将地图文件保存为图片(包括各种图片格式)
1,最近做了个地图文件输出图片的功能,思想主要就是利用MapControl的ActiveView中的out方法: 2代码如下:欢迎交流指正 SaveFileDialog m_save = new Sa ...
- Flask 学习系列(二)---Jinjia2模板
下面是一个jinjia2的简单模板的例子: <!DOCTYPE html> <html lang="en"> <head> <meta c ...
- kafka基础六
kafka中的高可用HA 1.replication副本 同一个partition会有一个leader和多个副本,这些副本存储的内容与leader相同,可以通过 server.properties 配 ...
- ES-windos环境搭建(3)-kibana
简介 Kibana是一个为ElasticSearch 提供的数据分析的 Web 接口.可使用它对日志进行高效的搜索.可视化.分析等各种操作. 下载 打开elasticseach官网,单击downloa ...
- 19/03/04 vue基础整理,webpack基础整理
gitUrl : https://gitee.com/jinyujiang/vue_basis_example.git (迭代更新) webpack : 有道云笔记分享 以及码云(迭代更新)
- Android:Service通知Activity更新界面
Android有四大组件,其中包括service和activity,那么在使用的过程中,我们最常遇到的问题是他们之间的通信问题. 1.首先Activity调用Service 这个是比较基础的,它有两种 ...
- SP2-0734: 未知的命令开头 "imp scott/..." - 忽略了剩余的行。
Oracle数据导入报错:SP2-0734: 未知的命令开头 "imp scott/..." - 忽略了剩余的行. 原因:进入sqlplus里是不能执行imp的(sqlplus不认 ...
- moment算本月开始日期和结束日期
moment算本月开始日期和结束日期 1.引入moment.js var vStartDate=new moment().add('month',addMonth).format("YYYY ...
- C#调用Lame.exe
string lameEXE = @"D:\lame3.100\lame.exe"; string lameArgs = "-b 128"; string wa ...
- 覆盖alert对话框-自制Jquery.alert插件
Javascript 代码: (function ($) { 'use strict'; window.alert = $.alert = function (msg) { var defaultOp ...