Squawk Virus: Difference between revisions
Jump to navigation
Jump to search
imported>Kmk21 Created page with "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 1..." |
imported>Kmk21 No edit summary |
||
Line 18: | Line 18: | ||
[[Category:ICPC Problems]] | [[Category:ICPC Problems]] | ||
[[Category: | [[Category:Ecna2015]] | ||
[[Category:Algorithm Easy]] | [[Category:Algorithm Easy]] | ||
[[Category:Implementation Easy]] | [[Category:Implementation Easy]] |
Latest revision as of 01:24, 7 November 2017
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.