← 返回 amazon 的题目列表Find Inventory Donor Fulfillment Centers Within Maximum Hops
类型:online_judge
An Amazon fulfillment network consists of fulfillment centers as nodes and bidirectional delivery routes as unweighted edges.
Given:
connections: a 2D integer array where [u, v] means there is a bidirectional route between centers u and v.
destination: the fulfillment-center ID that needs inventory.
maxStep: the maximum number of routes inventory may traverse to reach destination.
inventory: a dictionary mapping a fulfillment-center ID to its current item quantity.
Return all fulfillment-center IDs that can transfer inventory to destination, in any order.
A center belongs in the answer if and only if:
It is not destination itself.
Its inventory is greater than 0.
Its shortest-path distance in edges to destination is at most maxStep.
Example
connections = [[1, 2], [1, 3], [2, 4], [3, 4], [4, 5]]
destination = 4
maxStep = 1
inventory = {1: 2, 2: 0, 3: 5, 4: 3, 5: 6}
Output:
[3, 5]
Constraints
0 <= len(connections) <= 2 * 10^5
Node IDs are integers and may be non-contiguous.
0 <= maxStep <= 10^5
inventory contains at most 2 * 10^5 centers.
Example
Input
5
1 2
1 3
2 4
3 4
4 5
4 1
5
1 2
2 0
3 5
4 3
5 6
Output
3 5