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
题意:给出若干条边,让选出一个点,使该点到所有的点的最大距离最短,输出这个点和最大距离
题解:终于1A了……本来以为10分钟水出来的代码肯定会WA的……
这道题非常简单,就是模板题
除了disjoint,emmm样例不合理啊
代码如下:
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std; vector< pair<int,int> > g[];
int d[],vis[],n,ans,tmp1; void spfa(int u)
{
for(int i=;i<=n;i++)
{
d[i]=inf;
}
d[u]=;
queue<int> q;
q.push(u);
while(!q.empty())
{
int x=q.front();
q.pop();
vis[x]=;
int sz=g[x].size();
for(int k=;k<sz;k++)
{
int y=g[x][k].first;
int w=g[x][k].second;
if(d[x]+w<d[y])
{
d[y]=d[x]+w;
if(!vis[y])
{
q.push(y);
vis[y]=;
}
}
}
}
} int main()
{
while(scanf("%d",&n)&&n)
{
for(int i=;i<=n;i++)
{
g[i].clear();
}
ans=inf;
int m;
for(int i=;i<=n;i++)
{
scanf("%d",&m);
for(int j=;j<=m;j++)
{
int t,w;
scanf("%d%d",&t,&w);
g[i].push_back(make_pair(t,w));
}
}
for(int i=;i<=n;i++)
{
memset(vis,,sizeof(vis));
spfa(i);
int max1=,tmp2;
for(int j=;j<=n;j++)
{
max1=max(d[j],max1);
}
if(ans>max1)
{
ans=max1;
tmp1=i;
}
}
if(ans>=inf)
{
puts("disjoint");
}
else
{
printf("%d %d\n",tmp1,ans);
}
}
}


POJ1125 Stockbroker Grapevine(spfa枚举)的更多相关文章

  1. POJ1125 Stockbroker Grapevine

    Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a me ...

  2. POJ1125 Stockbroker Grapevine(最短路)

    题目链接. 分析: 手感不错,1A. 直接穷举的起点, 求出不同起点到其它点最短路中最长的一条的最小值(好绕). #include <iostream> #include <cstd ...

  3. poj1125 Stockbroker Grapevine Floyd

    题目链接:http://poj.org/problem?id=1125 主要是读懂题意 然后就很简单了 floyd算法的应用 代码: #include<iostream> #include ...

  4. POJ1125 Stockbroker Grapevine 多源最短路

    题目大意 给定一个图,问从某一个顶点出发,到其它顶点的最短路的最大距离最短的情况下,是从哪个顶点出发?须要多久? (假设有人一直没有联络,输出disjoint) 解题思路 Floyd不解释 代码 #i ...

  5. Stockbroker Grapevine(floyd+暴力枚举)

    Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31264 Accepted: 171 ...

  6. 【POJ 1125】Stockbroker Grapevine

    id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...

  7. Stockbroker Grapevine(最短路)

      poj——1125 Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36112 ...

  8. poj1125&zoj1082Stockbroker Grapevine(Floyd算法)

    Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Description Stockbrokers are known to ...

  9. POJ 1125 Stockbroker Grapevine

    Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33141   Accepted: ...

随机推荐

  1. 用dwr封装表单项提交表单

    首先,配置dwr环境,网上很多资料都说得很详细,这里就不写了. dwr封装form表单项,需要用到dwr定义的一个js方法:DWRUtil.getValues(yourform),这个方法可以返回一个 ...

  2. 解决spring 事务管理默认不支持SQLException等运行时异常

    公司同事在定位一个bug时,发现spring默认的事务只支持运行时异常的回滚,对于像SQLException这样的非运行时异常,默认的事务机制不能处理,于是找了下解决的办法:    1.在捕获SQLE ...

  3. 支付宝sdk集成

    支付宝开放平台 http://doc.open.alipay.com/doc2/detail?treeId=59&articleId=103563&docType=1 集成步骤: 1. ...

  4. 搭建JIRA汉化后乱码问题

    JIRA的简体中文乱码(使用了BIG5导致) 安装完JIRA汉化后发现一部分中文显示乱码,经检查:本来应该是UTF-8编码的却显示成Big5,Big5根本不支持简体中文的! 进入JIRA数据库后找到 ...

  5. 整数a整数b

    namespace ConsoleApplication6{ class Program { static void Main(string[] args) { while (true) { Cons ...

  6. U-boot分析与移植(3)----U-boot stage2分析

    一来到void start_armboot (void)函数,马上出现两个很重要的数据结构gd_t和bd_t 1.gd_t : global data数据结构定义,位于文件 include/asm-a ...

  7. SDRAM 之时序收敛(学习了特权老师)

    到现在我还是不太理解SDRAM的时序设置,但是可能蒙对了.(呵呵) 开发环境: quartus II 13.0   板子: DE2 EP2C35F672C6N 时序约束step 1:create cl ...

  8. 免费SSL证书 - Let's Encrypt申请(WINDOWS + IIS版)

    Let’s Encrypt 项目是由互联网安全研究小组ISRG,Internet Security Research Group主导并开发的一个新型数字证书认证机构CA,Certificate Aut ...

  9. Java微信公众平台开发(十五)--微信JSSDK的使用

    转自:http://www.cuiyongzhi.com/post/63.html 在前面的文章中有介绍到我们在微信web开发过程中常常用到的 [微信JSSDK中Config配置] ,但是我们在真正的 ...

  10. CentOS Firewall简单使用

    启动 systemctl start firewalld 停止 systemctl stop firewalld 获取 firewalld 状态 firewall-cmd --state 在不改变状态 ...