| Time Limit: 1000MS |
|
Memory Limit: 10000K |
| Total Submissions: 30454 |
|
Accepted: 16659 |
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
Test instructions
First, the topic may have more than one set of test data, the number of first behavioral brokers per test data N (when n=0, the input data ends), and then the next N lines describe the relationship of the 1<=i<=n broker to other brokers (teach you how to draw). Each line at the beginning of the number m for that line of the broker has the number of brokers friends (the node's out of the degree, can be 0), and then immediately after the m pairs of integers, each pair of integers expressed as a, a, indicating that the broker to the first broker to pass the information required B unit time (that is, the node I junction to The entire picture is a forward graph, that is, the arc Vij may not be equal to the arc Vji (the data is obvious, here is nonsense). When the composition is finished, ask for the minimum time to propagate the message to the entire broker network, starting at a certain point in the graph, and outputting the broker number and minimum time. The minimum time is determined by-from this broker (node), the last person in the entire broker network receives the message. If there is one or more brokers who cannot receive the message anyway, output "disjoint".
1#include <iostream>2#include <limits.h>3 using namespacestd;4 intnum;5 intmap[ -][ -];6 voidFloyd () {7 for(intI=0; i<num;i++){8 for(intj=0; j<num;j++){9 for(intk=0; k<num;k++){Ten if(map[j][i]!=int_max&&map[i][k]!=int_max&&j!=k) { One if(map[j][k]>map[j][i]+Map[i][k]) { Amap[j][k]=map[j][i]+Map[i][k]; - } - } the } - } - } - } + intMain () { -Cin>>num; + while(num) { A for(intI=0; i<num;i++){ at for(intj=0; j<num;j++){ -map[i][j]=Int_max; - } - } - for(intI=0; i<num;i++){ - inttmp; inCin>>tmp; - for(intj=0; j<tmp;j++){ to intStocker,time; +Cin>>stocker>>Time ; -map[i][stocker-1]=Time ; the } * } $ Floyd ();Panax Notoginseng intmin=int_max,max=0, St; - for(intI=0; i<num;i++){ themax=0; + for(intj=0; j<num;j++){ A if(max<map[i][j]&&i!=j) { themax=Map[i][j]; + } - } $ if(min>max) { $min=Max; -st=i+1; - } the } -cout<<st<<" "<<min<<Endl;WuyiCin>>num; the } - return 0; Wu}
Stockbroker Grapevine-poj 1125 (Floyd algorithm)