HBC24755柠檬树,数据结构,树,莫队[USACO 2010 Dec S]Apple Delivery题解 (bessiehastwocrispred)

淫家是湿人 算法基础篇 91 0
挑战自我,勇攀编程高峰!全网最全C++题库,助您成为编程达人。
Bessie has two crisp red apples to deliver to two of her friends in the herd. Of course, she travels the C (1

Bessie has two crisp red apples to deliver to two of her friends in the herd. Of course, she travels the C (1 <= C <= 200,000) cowpaths which are arranged as the usual graph which connects P (1 <= P <= 100,000) pastures conveniently numbered from 1..P: no cowpath leads from a pasture to itself, cowpaths are bidirectional, each cowpath has an associated distance, and, best of all, it is always possible to get from any pasture to any other pasture. Each cowpath connects two differing pastures P1_i P1 i ​ (1 <= P1_i P1 i ​ <= P) and P2_i P2 i ​ (1 <= P2_i P2 i ​ <= P) with a distance between them of D_i D i ​ . The sum of all the distances D_i D i ​ does not exceed 2,000,000,000. What is the minimum total distance Bessie must travel to deliver both apples by starting at pasture PB (1 <= PB <= P) and visiting pastures PA1 (1 <= PA1 <= P) and PA2 (1 <= PA2 <= P) in any order. All three of these pastures are distinct, of course. Consider this map of bracketed pasture numbers and cowpaths with distances: 3 2 2 [1]-----[2]------[3]-----[4] / / 7 /4 3 /2 / / [5]-----[6]------[7] 1 2 If Bessie starts at pasture [5] and delivers apples to pastures [1] and [4], her best path is: 5 -> 6-> 7 -> 4* -> 3 -> 2 -> 1* with a total distance of 12.

HBC24755柠檬树,数据结构,树,莫队[USACO 2010 Dec S]Apple Delivery题解
(bessiehastwocrispred)-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断学习,不断挑战,才能在编程领域中脱颖而出!全网最全C++题库,助您成为编程高手!

标签: HBC24755柠檬树 数据结构 莫队[USACO 2010 Dec S]Apple Delivery题解