TOJ 2857 Stockbroker Grapevine

描述

Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have to spread the rumours in the fastest possible way.

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.

输入

Your program will input data for different sets of stockbrokers. Each set starts with a line with the number of stockbrokers. Following this is a line for each stockbroker which contains the number of people who they have contact with, who these people are, and the time taken for them to pass the message to each person. The format of each stockbroker line is as follows: The line starts with the number of contacts (n), followed by n pairs of integers, one pair for each contact. Each pair lists first a number referring to the contact (e.g. a '1' means person number one in the set), followed by the time in minutes taken to pass a message to that person. There are no special punctuation symbols or spacing rules.

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.

输出

For each set of data, your program must output a single line containing the person who results in the fastest message transmission, and how long before the last person will receive any given message after you give it to this person, measured in integer minutes.
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.

样例输入

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

样例输出

3 2
3 10

题目来源

Southern African 2001

 

求一个Stockbroker把消息传递给其他Stockbroker所用的最短时间。

floyd求出两点之间消息传递的时间后,再求最短时间。

 

#include <stdio.h>
#define MAXN 105
#define inf 0x3f3f3f3fint N;
int map[MAXN][MAXN];
int ans[MAXN];void floyd(){for(int k=1; k<=N; k++){for(int i=1; i<=N; i++){for(int j=1; j<=N; j++){if(i==k||i==j)continue;if(map[i][k]!=inf && map[k][j]!=inf &&map[i][k]+map[k][j]<map[i][j]){map[i][j]=map[i][k]+map[k][j];}}}}
}
int main(int argc, char *argv[])
{int t,u,v,w;while(scanf("%d",&N)!=EOF && N){for(int i=1; i<=N; i++){for(int j=1; j<=N; j++){if(i==j)map[i][j]=0;else map[i][j]=inf;}}for(int u=1; u<=N; u++){scanf("%d",&t);while(t--){scanf("%d %d",&v,&w);map[u][v]=w;}ans[u]=-1;}floyd();for(int i=1; i<=N; i++){for(int j=1; j<=N; j++){if(map[i][j]>ans[i])ans[i]=map[i][j];}}int min=inf,index;for(int i=1; i<=N; i++){if(ans[i]<min){min=ans[i];index=i;}}if(min==inf){printf("disjoint\n");}else{printf("%d %d\n",index,min);}}return 0;
}

 

转载于:https://www.cnblogs.com/chenjianxiang/p/3534627.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/399750.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

input type='file' 上传文件时显示文件名及上传进度

https://blog.csdn.net/qq_36687640/article/details/78551217 1、input typefile 上传文件时显示文件名及上传进度 <input type"file" οnchange"showPreview(this)"> <p class"show"></p> <script> function show…

有意思的PHP代码块-面试经典_无需整理

为什么80%的码农都做不了架构师&#xff1f;>>> 不使用PHP自带反转函数&#xff0c;将字符串反转。//不用自带函数将其反转 方法一 $str "This is PHP"; $strArr explode( ,$str); $count count($strArr)-1; for($i$count;$i>0;$i--){$revStr . $s…

iOS开发之UITableView中计时器的几种实现方式(NSTimer、DispatchSource、CADisplayLink)

最近工作比较忙&#xff0c;但是还是出来更新博客了。今天博客中所涉及的内容并不复杂&#xff0c;都是一些平时常见的一些问题&#xff0c;通过这篇博客算是对UITableView中使用定时器的几种方式进行总结。本篇博客会给出在TableView中使用NSTimer或者DispatchSourcer中常见的…

html5爱心表白

http://js.itivy.com/jiaoben1892/index.html http://bangpai.sourceforge.net/main.html转载于:https://www.cnblogs.com/h07061108/p/html5_love.html

CentOS查看每个进程的网络流量

所需工具nethogs 安装&#xff1a;yum install -y nethogs 使用&#xff1a;nethogs eth0 sudo nethogs -s //按接收流量大小排序 如上图&#xff0c;PID一列就是进程的PID&#xff0c;PROGRAM就是显示进程或连接双方的端口号&#xff0c;前面红框是服务器的IP:端口&#xff0…

sqlserver中 事物 索引及视图

事务1、什么是事务事务是一个不可分割的工作逻辑单元&#xff0c;它包含了一组数据库的操作命令&#xff0c;并且所有命令作为一个整体一起向系统提交或撤销操作请求&#xff0c;即要么都执行&#xff0c;要么都不执行&#xff12;、事务的4个属性(1)、原子性(Atomicity)&#…

ubuntu下如何设置apache的启动和重启

ubuntu下如何设置apache的启动和重启 1、启动aoache服务 sudo /etc/init.d/apache2 start 2、重启apache服务 sudo /etc/init.d/apache2 restart 3、停止apache服务 sudo /etc/init.d/apache2 stop _______________________________ 注&#xff1a;a、这里的sudo可要可不要…

转:Java反射教程

原文来自于&#xff1a;http://www.importnew.com/9078.html 什么是反射&#xff1f;反射有什么用处&#xff1f; 1. 什么是反射&#xff1f; “反射&#xff08;Reflection&#xff09;能够让运行于JVM中的程序检测和修改运行时的行为。”这个概念常常会和内省&#xff08;Int…

浅入浅出数据结构(20)——快速排序

正如上一篇博文所说&#xff0c;今天我们来讨论一下所谓的“高级排序”——快速排序。首先声明&#xff0c;快速排序是一个典型而又“简单”的分治的递归算法。 递归的威力我们在介绍插入排序时相比已经见识过了&#xff1a;只要我前面的队伍是有序的&#xff0c;我就可以通过向…

django 1.8 官方文档翻译: 1-2-1 编写你的第一个Django应用,第1部分

编写你的第一个 Django 程序 第1部分 让我们通过例子来学习。 在本教程中&#xff0c;我们将引导您创建一个基本的投票应用。 它将包含两部分&#xff1a; 一个公共网站&#xff0c;可让人们查看投票的结果和让他们进行投票。一个管理网站&#xff0c;可让你添加、修改和删除投…

Newtonsoft.json中 linq to json 和序列化哪个快?

Newtonsoft.json是最常用的json序列化组件&#xff0c;当然他不是最快的&#xff0c;但是是功能最全的。。 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using Newtonsoft.Json.Linq; using Newtonsoft…

ubuntu 下 php 安装 zip

linux(ubuntu/centos)、windows安装php-zip扩展 PHP安装zip拓展&#xff0c;以及libzip安装问题

结对第一次作业

同学A : 031502630 - 吴松青 同学B : 031502644 - 邹星 第一次结对作业 本次作业的要求是设计一个方便部门纳新与学生选择部门的app&#xff0c;当然只是原型......刚开始怕要求实现的我们畏首畏尾&#xff0c;总得考虑到后期的实现的困难。最后老师提醒我们不需要实现后&#…

仿美团实现地域选择和城市列表

介绍 在开发O2O相关应用的时候&#xff0c;肯定会有定位&#xff0c;选择所在城市&#xff0c;选择地域&#xff0c;然后再向服务器请求该地区的相关数据&#xff0c;这时就需要我们提供一个导向让用户选择所在区域。 看来看去&#xff0c;最终还是选择模仿美团&#xff0c;感觉…

PHP5.5新特性

1 生成器 yield关键字 yield的中文文档在这里&#xff1a;http://php.net/manual/zh/language.generators.overview.php 查看文档&#xff0c;能知道yield的一个功能就是能有效的降低迭代的内存开销。比如官网的这个xrange例子&#xff1a; 12345678910111213141516171819<?…

Ubuntu16.04中php如何切换版本

其实就是一条Linux命令,如下: sudo update-alternatives --config php 会出现下面选项: There are 2 choices for the alternative php (providing /usr/bin/php).Selection Path Priority Status -------------------------------------------------------…

Java之杨辉三角的实现

今天突然想温习一下Java的基础&#xff0c;想了想就写写杨辉三角吧 1、直接法&#xff0c;利用二维数组 1 import java.util.Scanner;2 public class Second3 {4 public static void main(String[] args) {5 // TODO Auto-generated method stub6 Scanner …

MAC下面maven如何设置让其实下载源码

2019独角兽企业重金招聘Python工程师标准>>> Eclipse--->偏好设置&#xff0d;&#xff0d;&#xff0d;&#xff0d; >Maven--->download artifact source 转载于:https://my.oschina.net/u/2422498/blog/500292

chmod 777修改权限指令介绍

chmod 777修改权限指令介绍

EventBus使用详解(一)——初步使用EventBus

前言&#xff1a;EventBus是上周项目中用到的&#xff0c;网上的文章大都一样&#xff0c;或者过时&#xff0c;有用的没几篇&#xff0c;经过琢磨&#xff0c;请教他人&#xff0c;也终于弄清楚点眉目&#xff0c;记录下来分享给大家。 相关文章&#xff1a; 1、《EventBus使用…