Minimum Cost for Roads and Hospitals
Problem statement
Cities are labeled from 0 to cityCount - 1. A hospital can be built in any city for hospitalCost, and any listed undirected road can be built for roadCost.
Choose hospitals and roads at minimum total cost so every city can reach a hospital.
Function
minimumInfrastructureCost(cityCount: int, possibleRoads: int[][], hospitalCost: int, roadCost: int) → intExamples
Example 1
cityCount = 3possibleRoads = [[0,1],[1,2]]hospitalCost = 3roadCost = 2return = 7Case 1 exercises the documented deterministic contract.
Example 2
cityCount = 3possibleRoads = [[0,1]]hospitalCost = 2roadCost = 5return = 6Case 2 exercises the documented deterministic contract.
Example 3
cityCount = 5possibleRoads = [[0,1],[2,3]]hospitalCost = 6roadCost = 1return = 20Case 3 exercises the documented deterministic contract.
Constraints
1 <= cityCount <= 200000.0 <= possibleRoads.length <= 200000.- Costs are positive and the answer fits a signed 32-bit integer.