POJ 1125 Stockbroker Grapevine, pojstockbroker

Source: Internet
Author: User

POJ 1125 Stockbroker Grapevine, pojstockbroker
Stockbroker Grapevine

Time Limit:1000 MS
Memory Limit:10000 K
Total Submissions:26392
Accepted:14555

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

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

Source

Southern African 2001

Template question:
#include <iostream>using namespace std;#define INF 0x3f3f3f#define max(a,b) ((a)>(b)?(a):(b))int dp[105][105];int main(int i,int j,int k){    int n; while(scanf("%d",&n)!=EOF&&n) { for(i=1;i<=n;i++)for(j=1;j<=n;j++)dp[i][j]=INF; for(j=1;j<=n;j++) {     scanf("%d",&k);   for(i=1;i<=k;i++)   {int a,b;scanf("%d%d",&a,&b);dp[j][a]=b;   } }for(k=1;k<=n;k++)for(i=1;i<=n;i++)for(j=1;j<=n;j++)if(dp[k][j]<INF&&dp[i][k]<INF&&(dp[i][k]+dp[k][j])<dp[i][j]){  dp[i][j]=dp[i][k]+dp[k][j];}int min=INF,tot=0;for(i=1;i<=n;i++){ int now=-1; for(j=1;j<=n;j++) {if(i==j) continue;now=max(now,dp[i][j]); }if(now<min){min=now;tot=i;}}  printf("%d %d\n",tot,min);} return 0;}


Poj1125 good English Translation

Description,

Rumors that the stock broker knows the currency value. You have been spreading between simple development methods, accusing employers of tactical advantages in the stock market. For the maximum effect, you must spread rumors in the fastest way.

Unfortunately, for you, stock brokers only believe that the source of information comes from their "trust", which means you have to consider the rumors of structural contact. It takes a certain amount of time for a specific broker to pass rumors that everyone is at his colleague. Your task is to write a program that tells you which securities choose as the starting point, and how much time it will take to spread the rumors across the entire securities broker community. This is the person who receives the information at the required time.
Input,

Your program uses the input data as different stock brokers. Each set starts with a qualified stock broker. This is a line for every broker to include more people than they have access to. These people are the people who have time to send information to them. The format of each broker line is as follows: line from multiple contacts (n), followed by n pairs of integers, a pair of each ball. The first number lists each pair of reference contacts (such as "1", which refers to one person (SET), followed by the person who sent the information within a few minutes. There are no rules or spacing for special punctuation marks.

Everyone is a stockbroker from the number 1. The time to pass the information will be 1 to 10 minutes (including 1 year), and this number of contacts will range from 0 to a smaller number of stock brokers. The number of stocks ranges from 1 to 100. The input is a set of people whose stock brokers contain 0 (0.

Output

For each group of data, your program must output the People contained in a row, and the results are transmitted as quickly as possible. After how long will people get any information, you give this person an integer.
It may be because your program will receive a network connection to exclude some people, such as some people may be out of reach. If your program detects such a network disconnection, the simple output information is "convex ". Pay attention to the time to transmit information from a person to someone. It may not be the same time to transfer it from B to, if this transmission is possible.

ACM solution report

Category of a poj question
Mainstream algorithms:
1. Search // trace back
2. DP (Dynamic Planning)
3. Greedy
4. Graph Theory // Dijkstra, Minimum Spanning Tree, and network stream
5. Number Theory // solves the modulus linear equation
6. Calculate the area and perimeter of the joint of the geometric/Convex Shell with the same placement of the rectangle
7. Composite math // Polya Theorem
8. Simulation
9. Data Structure // check the collection and heap
10. Game Theory
1. Sorting
1423,169 4, 1723,172 7, 1763,178 8, 1828,183 8, 1840,220 1, 2376,
2377,238 0, 1318,187 1971,197, 1990,200 4, 2002,209 1, 2379 2,
1002 (character processing is required, and sorting can be done in a fast way) 1007 (stable sorting) 2159 (difficult to understand)
2231 2371 (simple sorting) 2388 (sequence statistics algorithm) 2418 (Binary sorting tree)
2. Search, backtracking, and traversal
2329
Simple: 1128,116 6, 1176,123 1, 1256,127 0, 1321,154 3, 1606,166 4,
1731,174 2, 1745,184, 1950,203, 2157,218 8, 2183,238 2, 2386,242 1, 6
Not easy: 1024,105 4, 1117,116 7, 1708,174 6, 1775,187 8, 1903,196 6, 2046,
2197,234 9
Recommended: 1011,119 0, 1191,141 6, 1579,163 2, 1639,165 9, 1680,168 3, 1691,
1709,171 4, 1753,1771, 1826,185 5, 1856,189 0, 1924,193 5, 1948,197 9, 1980,217 2331,233 1979, 1980 9, (similar to the maze), (higher requirements for pruning)
3. Calendar
1008 2080 (Be careful with such questions)
4. Enumeration
1387,141, 2245,232, 2363,238 1, 1650 6, (higher pruning requirements), (decimal precision problem)
5. Typical data structure Algorithms
Easy: 1182,165 6, 2021,202 3, 2051,215 3, 2227,223 6, 2247,235 2,
2395
Not easy: 1145,117 7, 1195,122 7, 1661,183 4
Recommended: 1330,133 8, 1451,147 0, 1634,168 9, 1693,170 3, 1724,198 8, 2004,
2010,211 9, 2274
1125 (fresh algorithm), 2421 (Minimum Spanning Tree of the graph)
6. Dynamic Planning
1037 A decorative fence,
1050 To the Max,
1088 skiing,
1125 Stockbroker Grapevine,
1141 Brackets Sequence,
1159 Palindrom ...... remaining full text>

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.