POJ1125 stockbroker Grapevine

Source: Internet
Author: User

Description

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

Unfortunately for your, stockbrokers only trust information coming from their "Trusted sources 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'll is to write a program This tells you which stockbroker to choose as Your starting point for the rumour, as Well as the time it'll take for the rumour to spread throughout the stockbroker community. This duration was measured as the time needed for the last person to receive the information.

Input

Your program would input data for different sets of stockbrokers. Each set starts with the number of stockbrokers. Following this was a line for each stockbroker which contains the number of people who they has contact with, who these PE Ople is, and the time taken for them-pass the message to each person. The format of each stockbroker line was 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 on the set), followed by the T IME in minutes taken-pass a message to the person. There is no special punctuation symbols or spacing rules.

The numbered 1 through to the number of stockbrokers. The time taken to pass the message on'll be between 1 and minutes (inclusive), and the number of contacts would range Between 0 and one less than the number of stockbrokers. The number of stockbrokers would 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 Tran Smission, and how long before the last person would receive any given message after you give it to this person, measured in Integer minutes.
It is possible this your program would receive a network of connections that excludes some persons, i.e. some people 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 are not necessarily the same as the time taken to PA SS it from B to A, if such transmission are possible at all.

Sample Input

32 2 4 3 52 1 2 3 62 1 2 2 253 4 4 2 8 5 31 5 84 1 6 4 10 2 7 5 202 2 5 1 50

Sample Output

3 23 10

Source

Southern African 2001

Positive solution: Floyd algorithm

Problem Solving Report:

A real water problem, given a graph, to find a source point so that the maximum distance to all points is the smallest.

The data range is small, run Floyd directly, water over.

1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstdlib>5#include <cstring>6#include <algorithm>7 using namespacestd;8 Const intMAXN = Max;9 Const intINF =500000000;Ten intA[MAXN][MAXN]; One intN; A  - intMain () - { the      while(1) { -scanf"%d",&n); -     if(n==0) Break; -     intx, y, z +  -      for(intI=1; i<=n;i++) +          for(intj=1; j<=n;j++) Aa[i][j]=inf; at  -      for(intI=1; i<=n;i++) { -scanf"%d",&x); -         if(!x)Continue; -          for(intj=1; j<=x;j++) scanf ("%d%d", &y,&z), a[i][y]=Z; -     } in      -  to      for(intk=1; k<=n;k++) +          for(intI=1; i<=n;i++) -          for(intj=1; j<=n;j++)  the             if(I!=j && j!=k) *A[i][j]=min (a[i][j],a[i][k]+a[k][j]); $ Panax Notoginseng     intans=inf,jilu=-1;BOOLflag=false; -      for(intI=1; i<=n;i++) the         { +         intnow=0; A          for(intj=1; j<=n;j++) the             if(I==J)Continue; +         //else if (a[i][j]>=inf) {printf ("disjoint\n"); flag=true; break;} -             Elsenow=Max (now,a[i][j]); $              $         if(Now<ans) {Ans=now; jilu=i;} -         } -  the      for(intI=1; I<=n &&!flag;i++) { -         intTotal=0;Wuyi          for(intj=1; j<=n;j++) { the         if(i!=j && a[j][i]>=inf && i!=jilu) total++;  -         } Wu         if(total==n-1) flag=true; -     } About  $     if(!flag) printf ("%d%d\n", Jilu,ans); -     Else{printf ("disjoint\n"); } -     } -     return 0; A}

POJ1125 stockbroker Grapevine

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.