Squawk Virus
Jump to navigation
Jump to search
This problem asks us to simulate a "gossip" network where every node broadcasts every message it receives 1 minute later.
The fact that we are limited to 100 nodes and only 10 steps is a hint that we can do some simple simulation.
Note that we cannot just add every message to a queue and walk through them all as the number of messages grows exponentially in a dense graph.
Instead we just track how many messages total that node will send to its partners at each timestep. Then walk each node, and increment the number of messages it's neighbors will send in the next minute by that amount.
- initialize "0" minute array to 0, but 1 for the start node
- walk every "source" node from previous minute, and increment the "current minute" value of its neighboring nodes by the amount in the previous "source" node's minute.
- repeat for t minutes
This is a good introduction to dynamic programming where
dp(node, time) = sum(neighbor(node), time-1)
runtime = 100 * 10 * 100.