POJ 1125 Stockbroker Grapevine

Source: Internet
Author: User

Stockbroker Grapevine
Time Limit: 1000 MS Memory Limit: 10000 K
Total Submissions: 23783 Accepted: 13067

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 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. Question 10: There is one rumor. There are n securities managers. Each manager can broadcast rumors to others (each manager can spread arbitrary data ). However, it takes time for each manager and other managers to disseminate data (for example, a needs 3 for B and a needs 4 for c ). Ask which manager is used as the starting point, and the maximum number of people can be spread, and the minimum time is allowed.

 


In fact, this question is like the shortest path between multiple point pairs (first, the maximum number of people must be reached, and second, the maximum and minimum among all the shortest paths must be met .. Good detour)

Then I used Floyd to calculate the shortest path of multiple sources, and then found the start point and the shortest time.

 

# Include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <algorithm> # include <queue> # define maxn 105 # define INF 1000000 using namespace std; int n, map [maxn] [maxn]; void init () {int I, j; for (I = 1; I <= n; I ++) {for (j = 1; j <= n; j ++) map [I] [j] = INF; map [I] [I] = 0 ;} for (I = 1; I <= n; I ++) {int t, a, B; scanf ("% d", & t); while (t --) {scanf ("% d", & a, & B); map [I] [a] = B ;}} void floyd () {int I, j, k; fo R (k = 1; k <= n; k ++) for (I = 1; I <= n; I ++) for (j = 1; j <= n; j ++) if (map [I] [k] + map [k] [j] <map [I] [j]) map [I] [j] = map [I] [k] + map [k] [j]; k = 0; int m = 0, z = INF; /* for (I = 1; I <= n; I ++) {for (j = 1; j <= n; j ++) cout <map [I] [j] <"; cout <endl;} */for (I = 1; I <= n; I ++) {int p = 0, t = 0; for (j = 1; j <= n; j ++) if (map [I] [j]! = INF) {if (map [I] [j]> t) t = map [I] [j]; // starts with every broker using t, the maximum propagation time is p ++; // p to record the number of other people each broker can pass} if (p> m) // The number of people is the first condition, so the number of people is large, exchange {m = p; k = I; z = t;} else if (p = m & t <z) // if the number of people is the same, take the shorter {m = p; k = I; z = t ;}} cout <k <"" <z <endl ;} int main () {while (cin> n) {if (n = 0) break; init (); floyd ();} return 0 ;}

 

Related Article

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.