Question
During the COVID pandemic, hospitals form a network represented as an undirected graph.
Each node in the graph represents a hospital, and each hospital is categorized as either:
- Surplus: has excess supply of COVID medication
- Shortage: lacks sufficient medication
- Neutral: neither surplus nor shortage
Medication can only be transferred from surplus hospitals to shortage hospitals, moving along the edges of the graph.
All surplus hospitals can begin dispatching supplies simultaneously.
Determine the minimum number of steps (edges traversed) required for all shortage hospitals to receive medication.
If a shortage hospital cannot be reached by any surplus hospital, it remains unserved.
Input/Output Example
Input:
- Graph G(V, E) with undirected edges
- Sets:
S = {nodes with surplus}
D = {nodes with shortage}
Approach:
- Perform **multi-source BFS** starting from all nodes in S
- Track visited nodes and shortest distance (depth)
- For each node in D, record the minimum step it is reached
- The answer is the **maximum** of those distances
If any node in D is not visited ⇒ not all demands can be fulfilled
Output:
- Minimum number of steps to satisfy all shortage nodes (or -1 if not possible)
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.
