G. Stockbroker Grapevine

Time Limit: 1000ms
Memory Limit: 10000KB

64-bit integer IO format: %lld      Java class name: Main

 
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 解题: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的更多相关文章

  1. POJ 1125:Stockbroker Grapevine

    Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64 ...

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

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

  3. POJ 1125 Stockbroker Grapevine

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

  4. Stockbroker Grapevine(floyd)

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

  5. poj 1125 Stockbroker Grapevine dijkstra算法实现最短路径

    点击打开链接 Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23760   Ac ...

  6. OpenJudge/Poj 1125 Stockbroker Grapevine

    1.链接地址: http://poj.org/problem?id=1125 http://bailian.openjudge.cn/practice/1125 2.题目: Stockbroker G ...

  7. POJ 1125 Stockbroker Grapevine【floyd简单应用】

    链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  8. Stockbroker Grapevine(最短路)

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

  9. Stockbroker Grapevine POJ 1125 Floyd

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

随机推荐

  1. Struts 2中访问Servlet API的几种方法小结

    1.使用ActionContext Action运行期间所用到的数据都保存在ActionContext中,例如session.客户端提交的参数等,ActionContext是Action的一个上下文对 ...

  2. Unity 360 旋转 缩放

    using UnityEngine; using System.Collections; public class SandR : MonoBehaviour { public GameObject ...

  3. JsonConvert对象实现json与对象之间的转换

    自己下载Newtonsoft.Json文件 使用JsonConvert对象转换 1. 2.添加引用到项目中,然后导入命名空间 3.就可以使用JsonConvert对象实现Json与类型之间的转换

  4. Fabric 简单使用

    Fabric 简单使用 最近公司组织压测系统,要在多台机子上部署代码,可是机子上的代码与生产环境不一样,需要修改代码,还有有问题的地方要修改,然后再发代码.这边一共有7台服务务器,重新发代码,要一台一 ...

  5. Java常用函数式接口--Consumer接口使用案例

    第一种方式: 第二种方式:

  6. Java GUI setSize()、setPreferredSize()的区别

    setSize().setPreferredSize()都可以设置组件的大小,但二者的使用有所不同. 1.setSize()的使用方式 setSize(int width,int height) se ...

  7. Java编程基础-反射

    一.java反射 1.反射:动态获取类的信息,以及动态调用对象的方法的功能.可以理解为动态看透类的能力. 2.主要功能:在运行时判断任意一个对象所属的类:在运行时构造任意一个类的对象:在运行时判断任意 ...

  8. jQuery选择器手册

    jQuery选择器手册 选择器 实例 选取 * $("*") 所有元素 #id $("#lastname") id="lastname" 的 ...

  9. IOS生成UUID

    /** * 生成GUID */ + (NSString *)generateUuidString{ // create a new UUID which you own CFUUIDRef uuid ...

  10. Ambiguous mapping. Cannot map 'registerController' method

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappi ...