POJ 1125--stockbroker Grapevine (Freud's shortest circuit)

Source: Internet
Author: User


Stockbroker Grapevine Time limit:1000MS Memory Limit:10000KB 64bit IO Format:%i64d & ; %i64u Submit Status Practice POJ 1125

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 way. 

Unfortunately for you, STO Ckbrokers only trust information coming from their "Trusted sources" the means E 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 p Eople 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 o f 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 Time 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 Messa GE transmission, and how long before the last person would receive any given message after you give it to this person, mea sured 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 P It from B to A, if such transmission are 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 2 7 5 2 0 2 2 5 1 5
  0

Sample Output

3 2
3 10


Test instructions (translation):

It is well known that the securities brokerage industry relies on excessive rumors. You need to figure out how to spread false intelligence in a stockbroker,
Give your employer an edge in the stock market. In order to get the maximum effect, you must spread the fastest way rumors. No
Fortunately for you, stockbroker information only trusts their "reliable sources", which means you must test before you spread the rumors
The structure of their contact. It requires a specific stockbroker and a certain amount of time to pass the rumor on to every colleague of his.
 your task will be to write a program that tells you which broker to choose as the starting point for rumors and how much time it takes
Brokers who spread rumors across society. This period is a measure of the time it takes for people in the past to receive information. 
  Enter 
 your program to include input data for multiple groups of stockbrokers. Each group starts with the number of stockbrokers. The next few lines are
There is some information that each broker touches with others, followed by n pairs of integers. The first number listed for each pair of integers refers to the
is a contact (for example, a ' 1 ' is the person who refers to number 1), followed by a message to the person
Take a minute's time. There are no special punctuation or whitespace rules. The number of each person is 1 to the number of brokers. The
The delivery time spent is from 1-10 minutes (including 10 minute). The number of stockbrokers is from 1 to 100.
 when the number of stock brokers entered is 0 o'clock, the program terminates. 
 output 
 In the case of each set of data, your program must output one line, including the information that has the fastest transmission, and in the most
After a person receives the message, the total amount of time used (in integer minutes). 
 Some of the relationships your program may receive will exclude some people, that is, some people may not be able to access them. If your journey
The sequence detects such a broken network, simply output the message "disjoint". Please note that the time spent is from
A passing message to B,b to pass information to a does not necessarily cost the same delivery time, but this kind of propagation is also possible. 

Idea: At first Test instructions not quite sure, thought is the smallest spanning tree, the result is wrong, later find the solution is the shortest way,

Use Freud to find the shortest distance between a little bit, then take it from everyone to the last person.

(That is, the longest time), and then take the minimum of these maximum values and record from which person to begin

The transmission is the answer, if there is no minimum value indicates that the graph is not connected.

The code is as follows:

#include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <
Algorithm> using namespace std;
#define S #define INF 0x3f3f3f3f int contact[s][s], n, t;
	void Floyd ()//To find the shortest path of all points {int I, j, K; for (k = 1; k <= T, k++) {for (i = 1; I <= t; i++) {for (j = 1; j <= T; j + +) {if (k = = I | | k = = J | |
			   i = = j) Continue;
			if (Contact[i][k] + contact[k][j] < Contact[i][j]) contact[i][j] = Contact[i][k] + contact[k][j];
	}}}} int main () {#ifdef OFFLINE freopen ("T.txt", "R", stdin), #endif int I, J, K, D, TT;
		while (~SCANF ("%d", &t) && t) {memset (contact, INF, sizeof);
			for (i = 1; I <= t; ++i) {contact[i][i] = 0;
			scanf ("%d", &n);
				while (n--) {scanf ("%d%d", &d, &AMP;TT);
			CONTACT[I][D] = TT;
		}} Floyd ();
		int min = inf, max, flag;
			for (i = 1; I <= t; i++) {max = 0; for (j = 1; j <= T; j + +) {if (Contact[i][j] > mAX) max = contact[i][j];
				The last person to get the message I sent (max)} if (Max < min) {//select min = max in which propagation time is least;
			flag = i;
		}} if (min = = inf)//non-unicom graph printf ("disjoint\n");
	else printf ("%d%d\n", flag, Min);
} return 0; }


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.