Question

In: Computer Science

Conquer the World Time limit: 8 seconds Bwahahahahaha!!! Your nemesis, the dashingly handsome spy Waco Powers,...

Conquer the World

Time limit: 8 seconds

Bwahahahahaha!!! Your nemesis, the dashingly handsome spy Waco Powers, has at last fallen to your secret volcano base’s deathtraps (or so you assume, being a little too busy to witness it firsthand). At long last, you are all set to CONQUER THE WORLD!

Nothing will stand in your way! Well, nothing except a minor problem of logistics. Your evil armies have announced that they will not continue carving their relentless path of destruction across the puny nations of the world without being paid. And unfortunately you are running low on cash – a volcano lair has many wonderful qualities, but “reasonably affordable” is not one of them. You have had to pull funds from the travel budget to pay your ungrateful underlings. Now you are not sure how you will actually get your armies into position to CONQUER THE WORLD.

You have a map of the nations of the world and all your available transport routes between them. Each route connects two nations and has a fixed cost per army that uses it. The routes are laid out such that there is exactly one way to travel between any two nations. You know the current position of each of your armies and how many you will need to place permanently in each nation in order to subjugate it. How can you move the armies into place as cheaply as possible so you can CONQUER THE WORlD?

Input

The first line of input contains an integer n (1 ≤ n ≤ 250000), the number of nations. This is followed by n − 1 lines, each containing three integers u, v, and c (1 ≤ u,vn, 1 ≤ c ≤ 106), indicating that there is a bidirectional route connecting nations u and v, which costs c per army to use.

Finally, another n lines follow, the ith of which contains two non-negative integers xi and yi, indicating that there are currently xi armies in nation i, and you need at least yi armies to end up in that nation in the final configuration. The total number of armies (the sum of the xi values) is at least the sum of the yi values, and no more than 106.

Output

Display the minimum cost to move your armies such that there are at least yi armies in nation i for all i.

Sample Input 1                                                      Sample Output 1

3
1 2 5
3 1 5
2 1
5 0
1 3

15

Sample Input 2 Sample Output 2

6
1 2 2
1 3 5
1 4 1
2 5 5
2 6 1
0 0
1 0
2 1
2 1
0 1
0 1

9

Q:What is Actually asked in the problem briefly define the problem and give its solution?

Solutions

Expert Solution

The problem statement decribes a situation which can be compared to the Travelling Salesman problem.

Here, the question states that there are 'n' country, let's refer to them as 'n' locations on a map. It goes on to state that these locations are in return connected by 'n-1' bidirectional paths, let suppose these paths are bidirectional roads. Now, between any two given locations (say 'u' and 'v'), there's a toll or a fee 'c' associated with anyone who wishes to use these connecting roads.

Once these inputs are acquired, we then have to provide number of armies we have present at each of these 'n' locations, along with number of armies that should be present in order to conquer that location. And in order to match the number of armies currently at a given location with the number of armies that should be there (in order to conquer it), it's understood that we'd have to move armies one-by-one to the respective locations to satisfy the required configuration. While doing so, we also have to keep in mind the cost 'c' for moving each army in either direction on any of the aforementioned roads.

Hence, the question requires the minimum cost which would be associated with achieving such a task.

Since it hasn't been specified which language the answer is supposed to be written in or if an algorithm is required, I wouldn't try attempting that part of your question in its entirety. Instead, let me outline an algorithm that would need to be built for it:

FOR EACH Country :

IF number of armies needed to conquer Country are less than required configuration :

    Find shortest path/ least cost to get required number of armies to Country

ELSE :

    Continue

  


Related Solutions

It is time to estimate your project’s budget. Your project sponsor has set a limit on...
It is time to estimate your project’s budget. Your project sponsor has set a limit on the amount of money you can spend. You know your budget will exceed that limit. Using the information covered in the required readings, describe the importance of properly establishing a project budget. What is the best method or methods to accurately estimate the budget for a unique project? What controls can you implement to keep your budget in check?
water displaced (mL) Time (seconds) 2 174 4 218 6 273 8 317 10 376 12...
water displaced (mL) Time (seconds) 2 174 4 218 6 273 8 317 10 376 12 421 14 456 16 502 18 584 20 614 22 679 water displaced (mL) Time (seconds) 2 201 4 246 6 292 8 331 10 397 12 436 14 489 16 541 18 584 20 631 22 702 water displaced (mL) Time (seconds) 2 194 4 229 6 285 8 328 10 382 12 413 14 469 16 512 18 590 20 622 22...
The patient came to your exercise sessions 80% of the time during the 8 week period....
The patient came to your exercise sessions 80% of the time during the 8 week period. Since she only needed to comply by 70%, she was granted the lap band surgery. After 12 weeks, she has lost 50 pounds and has eliminated her insulin and cholesterol medications but is still on the hypertension meds. Her knees also are starting to feel better. You meet with this person post-surgery for an exercise assessment and the post surgery program. This time, she...
The patient came to your exercise sessions 80% of the time during the 8 week period....
The patient came to your exercise sessions 80% of the time during the 8 week period. Since she only needed to comply by 70%, she was granted the lap band surgery. After 12 weeks, she has lost 50 pounds and has eliminated her insulin and cholesterol medications but is still on the hypertension meds. Her knees also are starting to feel better. You meet with this person post-surgery for an exercise assessment and the post surgery program. This time, she...
The patient came to your exercise sessions 80% of the time during the 8 week period....
The patient came to your exercise sessions 80% of the time during the 8 week period. Since she only needed to comply by 70%, she was granted the lap band surgery. After 12 weeks, she has lost 50 pounds and has eliminated her insulin and cholesterol medications but is still on the hypertension meds. Her knees also are starting to feel better. You meet with this person post-surgery for an exercise assessment and the post surgery program. This time, she...
The patient came to your exercise sessions 80% of the time during the 8 week period....
The patient came to your exercise sessions 80% of the time during the 8 week period. Since she only needed to comply by 70%, she was granted the lap band surgery. After 12 weeks, she has lost 50 pounds and has eliminated her insulin and cholesterol medications but is still on the hypertension meds. Her knees also are starting to feel better. You meet with this person post-surgery for an exercise assessment and the post surgery program. This time, she...
8. Your company's beta is 1.5 and market is 9%. In the same time treasury bill...
8. Your company's beta is 1.5 and market is 9%. In the same time treasury bill return is 4%. You have $300,000 Equity in the firm. You have $200,000 debt in your firm. The before tax cost of debt is 6%. The average tax rate is 40%. What is weighted average cost of capital of your firm?
8. Nominal and real wages have increased over time in the U.S. How fast will your...
8. Nominal and real wages have increased over time in the U.S. How fast will your nominal wage increase if you receive an increase each year that is comparable to what has occurred on average since 1929? About how long will it take the purchasing power of your wage to double if your real wage increases at the average rate experienced in the U.S. since 1929?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT