Stockbroker Grapevine
| Time Limit: 1000MS |
|
Memory Limit: 10000K |
| Total Submissions: 28851 |
|
Accepted: 16003 |
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
1#include <stdio.h>2#include <string.h>3 Const intinf=9999999;4 5 intedge[ -][ -],n;6 //int dis[500][500],path[500][500];7 8 voidFloyd ()9 {Ten inti,j,k; One for(k=1; k<=n;k++) A { - for(i=1; i<=n;i++) - { the for(j=1; j<=n;j++) - { - if(Edge[i][j]> (edge[i][k]+Edge[k][j])) - { +edge[i][j]=edge[i][k]+Edge[k][j]; - } + } A } at } - return; - } - - intMain () - { in inti,j,k, x, y; - intAns1,ans2; to while(SCANF ("%d", &n)!=eof && n!=0) + { - for(i=1; i<=n;i++) the for(j=1; j<=n;j++) * { $edge[i][j]=INF;Panax Notoginseng } - for(i=1; i<=n;i++) edge[i][i]=0; the for(i=1; i<=n;i++) + { Ascanf"%d",&k); the for(j=1; j<=k;j++) + { -scanf"%d%d",&x,&y); $edge[i][x]=y; $ } - } - Floyd (); the - /*For (i=1;i<=n;i++)Wuyi { the For (j=1;j<=n;j++) - { Wu printf ("%d", edge[i][j]); - } About printf ("\ n"); $ }*/ - - -Ans2=INF; A for(i=1; i<=n;i++) + { the intma=edge[i][1]; - for(j=2; j<=n;j++) $ { the if(edge[i][j]>Ma) theMa=Edge[i][j]; the } the if(ma<ans2) - { inAns2=Ma; theans1=i; the } About } the if(ans2==INF) theprintf"disjoint\n"); the Else +printf"%d%d\n", ans1,ans2); - } the return 0;Bayi}View Code
Floyd algorithm poj1125