Problem · Tree
Minimum Satellite Data Transfer Iterations
Learn this problemProblem statement
A space organization has numSatellite satellites with IDs from 0 to numSatellite - 1. Satellite 0 initially has a data packet that must reach every satellite.
The directed pairs in connections form a tree rooted at satellite 0. For each pair [sender, receiver], sender may transfer the data directly to receiver.
Transfer model
- During one iteration, every satellite that had the data at the start of that iteration may transfer it to at most one direct child that does not yet have it.
- All transfers selected for an iteration finish together at the end of that iteration.
- A satellite that receives the data may begin forwarding it in the next iteration.
- A satellite may send again in later iterations until all of its direct children have received the data.
- Each satellite has at most
maxSatellitesdirect children.
You may choose the order in which every satellite contacts its children. Return the minimum number of iterations needed for all satellites to receive the data.
Function
minimumDataTransferIterations(numSatellite: int, connections: int[][], maxSatellites: int) → intExamples
Example 1
numSatellite = 2connections = [[0,1]]maxSatellites = 1return = 1Satellite 0 transfers the data to satellite 1 in the first iteration.
Example 2
numSatellite = 6connections = [[0,1],[0,2],[1,3],[1,4],[3,5]]maxSatellites = 2return = 3One optimal schedule is:
- Satellite
0sends to1. - Satellite
0sends to2, while1sends to3. - Satellite
1sends to4, while3sends to5.
All satellites have the data after three iterations.
Example 3
numSatellite = 5connections = [[0,1],[0,2],[0,3],[0,4]]maxSatellites = 4return = 4Satellite 0 can transfer to only one child per iteration. It therefore needs four iterations to contact all four children.
Constraints
2 <= numSatellite <= 10^4connections.length == numSatellite - 1- Every connection is a two-element array
[sender, receiver]with distinct IDs in the range0throughnumSatellite - 1. - The directed connections form a tree rooted at satellite
0, so every other satellite is reachable exactly once. 1 <= maxSatellites < numSatellite- Every satellite has at most
maxSatellitesdirect children.