POJ1125 Stockbroker Grapevine 多源最短路 Floyd

ComfyUI全自动换装工作流:从零到一的实战指南 本文提供了一份详细的ComfyUI全自动换装工作流实战指南。从环境配置、模型准备到核心工作流架构的逐步拆解,手把手教你搭建一条高效的AI换装流水线。文章深入解析了从输入、预处理、融合到输出的四步核心逻辑,并分享了关键参数调优与进阶技巧,旨在帮助电商从业者、内容创作者及AI爱好者轻松实现高质量、高效率的“一键换装”。 阅读详情

Description

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.

Input

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.

Output

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.

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

题目大意

有n个人,每个人有t个关系,表示可以把消息用多长时间传递给谁。求用谁传消息最快,最快多少时间。

解题思路

多源最短路,看下谁最快就行了。Floyd算法。

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF = 1000000000;
const int maxn = 110;
int eg[maxn][maxn];
int n;
int main()
{
    while(scanf("%d",&n) && n) {
        //init
        for(int i = 0 ; i < maxn ; i ++) {
            for(int j = 0 ; j < maxn ; j ++) eg[i][j] = INF;
        }
        for(int i = 1 ; i <= n ; i ++) {
            int t;
            scanf("%d",&t);
            while(t--) {
                int a,b;
                scanf("%d%d",&a,&b);
                eg[i][a] = b;
            }
        }
        for(int k = 1 ; k <= n ; k ++) {
            for(int i = 1 ; i <= n ; i ++) {
                for(int j = 1 ; j <= n ; j ++) {
                    eg[i][j] = min(eg[i][j],eg[i][k]+eg[k][j]);
                }
            }
        }
        int mi = INF;
        int node;
        bool noone = true;
        for(int i = 1 ; i <= n ; i ++) {
            int ma = -1;
            for(int j = 1 ; j <= n ; j ++) {
                if(j == i) continue;
                if(ma < eg[i][j]) ma = eg[i][j];
            }
            if(ma < mi) {mi = ma;node = i;}
            if(ma != INF) noone = false;
        }
        if(noone) printf("disjoint\n");
        else printf("%d %d\n",node,mi);
    }
    return 0;
}
2篇5章1节:实验流行病学的核心特征和设计原则 本文系统阐释实验流行病学的核心定义、四大核心特征、四大基本原则及主流设计类型,结合骨科、肿瘤科、儿科、精神科、内外妇儿及公共卫生等多学科临床实践案例,具象化解读人为干预、随机分组、平行对照、前瞻性设计的核心内涵与应用价值。同时,规范梳理对照、随机、盲法、重复四大研究基本原则,详细介绍临床试验、现场试验、社区试验三类主流研究设计的适配场景与应用差异。 阅读详情

相关推荐

单视图几何Vanish Point(消失点/灭点)计算方法——Robert_T_Collins(罗伯特·柯林斯)算法

单视图几何Vanish Point(消失点/灭点)计算方法——Robert_T_Collins(罗伯特·柯林斯)算法

beyond951的博客 7342

POJ-1125 Stockbroker Grapevine floyd

计算出是否存在某个源点发出的信息能够到达所有其他点,并且输出满足该情况下的整个路径中最长路径最小的那个源点以及那条最长的边。 floyd直接计算,在通过遍历整个二维数组来确定这个最后结果。 代码如下: #include &lt;cstdlib&gt; #include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;algo...

weixin_34228662的博客 150

通俗易懂的图解二叉搜索树、AVL树和红黑树

搜索是一种很常见的需求,当数据较多时,如何找到目标对象时,即需要搜索查找。 那么如何快速找到目标呢,最朴素的思想就是暴力查找,一个一个对比。 显然,当数据量增大时,我们需要优化查找方法获取更快的查找速度,我们可以通过维护一个有序数组,从而实现二分查找,查找速度从O(n)降为O(longn)。 但是数组并不便于插入和删除,链表便成为了最好的选择。 既然是采用二分查找,那么不如直接按照查找的步骤维护一种数据结构,于是二叉搜索树出现了。 二叉搜索树的性质为: 若左子树不为空,则左子树上所有节点值都小于根结点值;

暗色光的博客 759

POJ 百练 1125: Stockbroker Grapevine

特别注意:1.每次读入新一组数据时,要对数组d[n][n]初始化,否则会影响后面的结果;2.本题的思路类似于Dijkstra算法。 时间限制: 1000ms 内存限制: 65536kB 描述 Stockbrokers are known to overreact to rum

youyang1991的专栏 735

开源数显表

开源数显表,广泛应用于车床、铣床、磨床、镗床、火花机、线切割等。市面上此类液晶数显表多数都是基于此项目。 一、基本配置 硬件 主控:STM32F407VGT6 LCD:群创AT070TN92 显示驱动:RA8875 光栅尺:3 x 输入(X/Y/Z) 串口:1 x MAX3232 继电器:2 x 输出 存储:AT24C64 模拟输入:LM324C 电源:AC 220V 软件 工程版本:Keil 5 STM32库:V1.4.0 图形界面:uCGUI 多语言支持:中文、英文 二、项目文

m0_70934529的博客 443

SWIFT报文实战指南:从MT700到MT799的信用证操作全解析

本文深入解析了国际贸易中信用证操作的核心SWIFT报文流程,从开证的MT700到各类通知、修改及结算报文(如MT707、MT730、MT754、MT732/734等)。通过实战案例与关键字段拆解,指导外贸与银行从业者精准处理报文,规避风险,并探讨了利用自动化工具提升处理效率的方法,助力保障跨境交易顺畅。

weixin_29015801的博客 908

[POJ1125 Stockbroker Grapevine]

[题目来源]:Southern African 2001 [关键字]:图论 [题目大意]:股票经纪人要在一群人中散布一个传言,传言只能在认识的人中传递,题目将给出人与人的关系(是否认识),以及传言在某两个认识的人中传递所需的时间,要求程序给出以哪个人为起点,可以在好事最短的情况下,让所有人收到消息。 //============================================...

weixin_30949361的博客 348

Jetson编译安装pycuda

可使用nvcc --version查看是否有信息输出,若没有,且安装cuda的情况下,需要手动将CUDA 的路径添加到环境变量中。编译生成_pvt_struct.cpython-38-aarch64-linux-gnu.so文件。基于jetson orin nano jetpack512模块上安装pycuda。4、获取pycuda源码(版本根据实际情况获取)2、进入conda环境并安装cuda工具包。9、若未检测出来需要清除并强制编译。7、编译成功后安装pycuda。5、配置编译并设置环境变量。

qq_48175141的博客 977

POJ1125-Stockbroker Grapevine

全解题报告索引目录 -> 【北大ACM – POJ试题分类】 转载请注明出处:http://exp-blog.com ------------------------------------------------------------------------- 提示:最短路问题,Floyd算法,相比于Bellman和Dijkstra,我认为是最接近人类自然思维的算法,O...

ζёСяêτ - 小優YoU 9234

Python 爬虫实战:爬取豆瓣读书评论并分析

摘要:本文以豆瓣读书《活着》评论数据为例,详细讲解Python爬虫开发与文本分析全流程。首先通过requests库爬取评论数据,解决分页、反爬等问题;然后利用BeautifulSoup解析页面提取评论内容、评分等核心信息;最后结合jieba进行关键词提取、snownlp完成情感分析,并通过可视化展示结果。分析显示该书评分以5星为主(占比70%),正面评论达82%,核心关键词为"活着""余华""生命"。全文包含完整代码与详细解析,帮助读者掌握非结构化

2503_91057718的博客 1504

13. MIC配置

恒玄BES2700,支持3个MIC。

雪飞_海 933

POJ 1125 Floyd

题目大意: 直接用 输入示例说明吧, 3 2 2 4 3 5 2 1 2 3 6 2 1 2 2 2 表示 第一行表示一个股票经纪人需要向三个人传消息,第二行表示 第一个人有两个朋友, 向第二个朋友传消息需要 时间4 ,向第三个朋友发消息需要时间 5,第二行表示 第二个人有两个朋友,向第一个人传消息需要时间2,向第三个人传消息需要时间 6,第三行同样。 求 能

ChallenChenZhiPeng的专栏 574

Linux系统安全学习手册

Linux反弹shell Linux系统应急响应 Linux服务器安全加固 Linux下的用户、组和权限 Linux中的gcc Linux中su和sudo的用法和区别 Linux系统python2与python3共存 Linux中grep工具的使用 Linux中环境变量的设置 Linux中常见的150个命令(干货) Linux中编写Shell脚本 LNMP环境搭建Wordpress博客 LAMP环境搭建一个Discuz论坛 Linux运维比较常用的一些脚本 Linux系统中安装软

谢公子的博客 7541

POJ 1125 Stockbroker Grapevine(Floyd多源最短路)

Description 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

楠先生 605

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

POJ 1125 Stockbroker Grapevine (多源最短路Floyd)

题目链接POJ1125题目大意有N个股票经济人可以互相传递消息,他们之间存在一些单向的通信路径。现在有一个消息要由某个人开始传递给其他所有人,问应该由哪一个人来传递,才能在最短时间内让所有人都接收到消息。若不存在这样一个人,则输出disjoint。分析多源最短路问题,用Floyd算法解决。 对于每个结点,若它到其他每个结点的最短路均为有限值,则它可以用来传播消息,传播消息的所需的时间为最后一个知道

歪歪T的拿金之路 381

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

POJ 1125 Stockbroker Grapevine floyd多源最短路,选取一个点,使最大边的权值是最小的

第一个输出选取的点,然后在输出选取的点到所有边的权值中最大的。 选点如何选择??? 一个点到其余所有点的边都有一个最大值,这个最大值最小即可 #include #include #include #include #include #define inf 0x3f3f3f3f using namespace std; int d[110][110]; void init(int

sdut_jean的博客 501

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

最短路poj 1125

题目:poj1125Stockbroker Grapevine 题意:此题题意远比题目难 首先,题目可能有多组测试数据,每个测试数据的第一行为经纪人数量N(当N=0时,输入数据结束),然后接下来N行描述第i(1 分析:说的很清楚了,最短路算法基本都能水过,可以选熟悉的用 强调:floyd算法用前一定初始化为INF,否则会很惨。 代码: #include

大神养成中..... 7777

【POJ 1125】Stockbroker Grapevine

【POJ 1125】Stockbroker Grapevine 最短路 只是这题数据非常水。。主要想大牛们试试南阳OJ同题 链接例如以下: http://acm.nyist.net/JudgeOnline/talking.php?pid=426&page=2 数据增大非常多 用到非常多东西才干过 (弱没过,。。 这题就是求最短路寻找全部通路中最大权的最...

aofan9566的博客 147

POJ 1125 Stockbroker Grapevine

POJ 1125 Stockbroker Grapevine #include <iostream> #include <fstream> #include <string> #include <algorithm> ...

dayong9372的博客 118

POJ 1125 floyd算法 Stockbroker Grapevine

题目链接:http://poj.org/problem?id=1125 分析:题意是求最小总时间.则我们要利用的也应该是任何两个人之间传递的最小时间,所以,先要用floyd算法处理.然后,发出这个消息时,有n种选择(n个人),假如先传给i, 那么map[i][1......n] (map[i][j]表示i传到j的最小时间) 中的最大那个,假如是x[i],那么这种情况下x[i]是肯定最后知道的,

PWZER 923

POJ 1125Stockbroker Grapevine(floyd最短路)

题目地址:

scf0920 771

[poj 1125]Stockbroker Grapevine[Floyd最短路]

题意: 股票经纪人之间传递谣言. 给出一个股票经纪人的联系网络: a联系到b用时w. 求: 选择哪一个人作为谣言的源头可以使得谣言传到所有人最快, 以及传到所有人所用时间. 思路: Floyd算法可以求出全源最短路. 只要枚举每一个源s, 记录s到其他人的最大时间t, 比较t, 最小的那个对应的s即为所求. #include #include using namespace std

以中有足乐者... 1137

POJ 1125 Stockbroker Grapevine(Floyd)

题目地址:http://poj.org/problem?id=1125 题意:有一群买股票的人,如何从中间选择一个人使得所有人都知道这个消息的时间最短 思路:先把N个人中最短路径中最长的算出来,再从N个人最长的路径中找出最短的 AC代码: #include #include #include using namespace std; const int inf = 0x3f3f3f3

Java识堂,一个有干货的微信公众号 333

POJ 1125 Stockbroker Grapevine floyd水题

传送门:POJ1125 题意:有n个人,给出他们之间互相传送信息需要的时间,让你选出某个人,使信息他开始传遍所有人所需的时间最少。求这个人和所需的最短时间。 思路:用floyd求出任意两人之间的最短路,然后筛选一遍就好了。当然也可以用dijkstra或者spfa,不过思路大体相同,算法不同罢了。 代码: #include #include #include #include #includ

WA是一笔财富 291

POJ1125 Stockbroker Grapevine【Floyd】

Description 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 spre

胡小涛的博客 276

poj 1125 Stockbroker Grapevine(多源最短路)

题目链接:http://poj.org/problem?id=1125 思路:用Floyd预处理任意两点之间的最短距离,然后枚举每个点到其他所有点的最长距离,求出最小距离,如果最小距离不为INF,总有解,输出即可。 在这里,注释一下Floyd的动态规划思想: dp[k][i][j]表示i和j之间可以通过编号为1...k的节点的最短路径。初值dp[0][i][j]为原图的邻接矩阵。

To be excellent! 293
上一篇: 最小生成树 Prim算法 Kruskal算法
下一篇: POJ3259 Wormholes Floyd判负圈
Bill_Utada
博客等级 码龄12年 43粉丝 133原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值