Stockbroker Grapevine
| Time Limit:1000 MS |
|
Memory Limit:10000 K |
| Total Submissions:23282 |
|
Accepted:12738 |
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 (random SIVE), and the number of contacts will range between 0 and one less than the number of stockbrokers. the number
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
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
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
This is a bare floyd, which is basically used to familiarize yourself with the template. Your program contains the input data of multiple groups of stock brokers. Each group starts with the number of stock brokers. The next few lines are information that every broker has access to other people, including who these people are and the time required to send the message to them. The contact information of each broker with others is in the following format: the first number at the beginning indicates a total of n contacts, followed by n pairs of integers. The first number listed in each pair of integers refers to a contact (for example, a '1' refers to a person numbered 1 ), the second step is to take minutes to pass a message to the person. There are no special punctuation or space rules.
The number of each person is 1 to the number of brokers. The transfer time is from 1 to 10 minutes (including 10 minutes ). The number of brokers ranges from 1 to 100. When the number of people who enter the stock broker is 0, the program is terminated.
Output
For each group of data, your program must output one line, including the person with the highest transmission speed, and after the last person receives the message, the total time used (calculated in integer minutes) is as follows:
# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # define inf 1000000 // infinite using namespace std; int a [101] [101]; int num; void floyd () {// standard floyd template for (int k = 1; k <= num; k ++) for (int I = 1; I <= num; I ++) for (int j = 1; j <= num; j ++) {if (a [I] [k] + a [k] [j] <a [I] [j]) a [I] [j] = a [I] [k] + a [k] [j] ;}} int main () {int I, j; int m, contact, time, minTime, max, person; while (scanf ("% d", & num) {for (I = 1; I <= num; I ++) for (j = 1; j <= num; j ++) {// create a critical table if (I! = J) a [I] [j] = inf; // indicates that the initial time and other else a [I] [j] are not connected. = 0; // The distance to yourself is 0} for (I = 1; I <= num; I ++) {scanf ("% d", & m ); for (j = 1; j <= m; j ++) {scanf ("% d", & contact, & time ); a [I] [contact] = time; // The time that the contact was uploaded from the broker I to the contact is the input time} floyd (); minTime = inf; for (I = 1; I <= num; I ++) {max = 0; for (j = 1; j <= num; j ++) {if (a [I] [j]> max) max = a [I] [j];} if (max <minTime) {minTime = max; person = I ;}} if (minTime! = Inf) printf ("% d \ n", person, minTime); else printf ("disjoint \ n");} return 0 ;}