Poj_1125 Stockbroker Grapevine

Source: Internet
Author: User

Stockbroker Grapevine
Time Limit: 1000 MS
Memory Limit: 10000 K
Total Submissions: 20810
Accepted: 11278
 
 
Description
Stockbrokers are known to overreact to rumours. you havebeen contracted to develop a method of spreading disinformation amongst thestockbrokers to give your employer the tactical edge in the stock market. formaximum 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 thestructure of their contacts when starting a rumour. it takes a certain amountof time for a specific stockbroker to pass the rumour on to each of hiscolleagues. your task will be to write a program that tells you whichstockbroker to choose as your starting point for the rumour, as well as thetime it will take for the rumour to spread throughout the stockbrokercommunity. this duration is measured as the time needed for the last person toreceive the information.
Input
Your program willinput data for different sets of stockbrokers. each set starts with a line withthe number of stockbrokers. following this is a line for each stockbroker whichcontains 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 ofeach stockbroker line is as follows: The line starts with the number ofcontacts (n), followed by n pairs of integers, one pair for each contact. eachpair lists first a number referring to the contact (e.g. a '1' means personnumber one in the set), followed by the time in minutes taken to pass a messageto that person. there are no special punctuation symbols or spacing rules.

Each person is numbered 1 through to the number of stockbrokers. the time takento pass the message on will be between 1 and 10 minutes (random SIVE), and thenumber of contacts will range between 0 and one less than the number ofstockbrokers. the number of stockbrokers will range from 1 to 100. the input isterminated by a set of stockbrokers containing 0 (zero) people.
Output
For each set of data, your program must output a singleline containing the person who results in the fastest message transmission, andhow long before the last person will receive any given message after you giveit to this person, measured in integer minutes.
It is possible that your program will receive a network of connections thatexcludes some persons, I. e. some people may be unreachable. if your programdetects 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 notnecessarily the same as the time taken to pass it from B to A, if such transmissionis 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
Source
Southern African2001
 
Question:
This question is not difficult, but it is difficult to understand the meaning of the question. It is about message transmission. The first line shows the number of people who send the message n, the first number in the next n rows indicates the number and time that a person (I) can transmit in m (a, B). Ask the person who sent the message as quickly as possible, the time is the maximum.
Solution:
Because the data volume of this question is small, you can use the Floyd-Warshall algorithm to obtain the minimum distance between each two points. Then you can traverse the answer once.
Code:
 
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Deprecision MAX 103
# Define VALUE 0 xffffff
Using namespace std;
 
Int g [MAX] [MAX];
Int d [MAX];
Bool used [MAX];
 
Int min (int x, int y)
{
Return x <y? X: y;
}
Void Floyd (int n)
{
Int I, j, k;
For (k = 1; k <= n; k ++)
For (I = 1; I <= n; I ++)
For (j = 1; j <= n; j ++)
G [I] [j] = min (g [I] [j], g [I] [k] + g [k] [j]); // obtain the minimum value between any two points
}
 
Int main ()
{
Int ts;
Int I, j;
Int maxvalue, maxtime, t;
While (true)
{
Scanf ("% d", & ts );
If (ts = 0) break;
// Memset (g, 0, sizeof (g ));
For (I = 1; I <= ts; I ++)
For (j = 1; j <= ts; j ++)
G [I] [j] = VALUE;
 
For (I = 1; I <= ts; I ++)
{
Int n;
Scanf ("% d", & n );
G [I] [I] = 0;
While (n --)
{
Int no, time; // time and number
Scanf ("% d", & no, & time );
G [I] [no] = time; // create a graph
}
}
Floyd (ts );
Maxtime = VALUE;
For (I = 1; I <= ts; I ++)
{
Maxvalue = 0;
For (j = 1; j <= ts; j ++)
{
If (g [I] [j]> maxvalue)
{// Obtain the longest edge
Maxvalue = g [I] [j];
}
}
If (maxvalue <maxtime)
{
Maxtime = maxvalue;
T = I;
}
}
If (maxtime = VALUE)
{
Printf ("disjoint \ n ");
}
Else
{
Printf ("% d \ n", t, maxtime );
}
 
}
Return 0;
}
Author: CSDN515

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.