1
var networkBecomesIdle = function (edges, patience) {3
for (let [edge, neighbor] of edges) {4
if (!(edge in graph)) graph[edge] = [];5
graph[edge].push(neighbor);6
if (!(neighbor in graph)) graph[neighbor] = [];7
graph[neighbor].push(edge);10
// Initialize queue with server 017
let current = q.pop();18
if (current in complete) continue;19
complete[current] = seconds * 2;20
for (let edge of graph[current]) {21
if (complete[edge]) continue;30
let servers = Object.keys(graph).length;33
for (let i = 1; i < servers; i++) {34
let timeToComplete = complete[i];35
let resendInterval = patience[i];37
// If timeToComplete == 4 and resendInterval == 2, the msg will be resent 1 time at second 2 and not second 438
// If timeToComplete == 5 and resendInterval == 2, the msg will be resent 2 times at second 2 and second 439
// Hence we use Math.ceil(...) - 140
let resendCount = Math.ceil(timeToComplete / resendInterval) - 1;42
let seconds = timeToComplete + resendInterval * resendCount;43
maxSeconds = Math.max(maxSeconds, seconds);45
return maxSeconds + 1;