Tap here to switch tabs
Problem
Submissions

Problem: The Time When the Network Becomes Idle

Try to solve the The Time When the Network Becomes Idle problem.

Statement

There is a network of nn servers labeled from 00 to n−1n - 1. You are given a 22D integer array edges, where each edges[i] = [u_i, v_i] represents a bidirectional communication link between server uiu_i and server viv_i. It takes 11 second for a message to travel across any single edge. The network is connected, meaning every server can communicate with every other server directly or indirectly.

Server 00 is designated as the master server, and all other servers from 11 to n−1n - 1 are data servers. Each message sent to the master server travels along the shortest path. Upon receiving a message, the master server instantly processes it and sends an immediate reply back to the originating server along the same shortest path in reverse.

You are also given an integer array patience of length nn. At the start of second 00, every data server sends a single message to server 00. Each data server ii will continue monitoring for a reply. If patience[i] seconds have elapsed since its most recent transmission and it has not yet received any reply, server ii will resend the message. This resending repeats every patience[i] seconds until server ii receives its first reply. Once a data server receives any reply, it immediately stops sending messages.

Return the earliest second at which the network becomes idle, meaning there are no messages in transit between any servers.

Constraints:

  • n == patience.length

  • 2≤n≤1052 \leq n \leq 10^5

  • patience[0] =0= 0

  • 1≤1 \leq patience[i] ≤105\leq 10^5 for 1≤i<n1 \leq i < n

  • 1≤1 \leq edges.length ≤min⁡(105,n⋅(n−1)2)\leq \min(10^5, \frac{n \cdot (n - 1)}{2})

  • edges[i].length =2= 2

  • 0≤ui,vi<n0 \leq u_i, v_i < n

  • ui≠viu_i \neq v_i

  • There are no duplicate edges.

  • Each server can directly or indirectly reach another server.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: The Time When the Network Becomes Idle

Try to solve the The Time When the Network Becomes Idle problem.

Statement

There is a network of nn servers labeled from 00 to n−1n - 1. You are given a 22D integer array edges, where each edges[i] = [u_i, v_i] represents a bidirectional communication link between server uiu_i and server viv_i. It takes 11 second for a message to travel across any single edge. The network is connected, meaning every server can communicate with every other server directly or indirectly.

Server 00 is designated as the master server, and all other servers from 11 to n−1n - 1 are data servers. Each message sent to the master server travels along the shortest path. Upon receiving a message, the master server instantly processes it and sends an immediate reply back to the originating server along the same shortest path in reverse.

You are also given an integer array patience of length nn. At the start of second 00, every data server sends a single message to server 00. Each data server ii will continue monitoring for a reply. If patience[i] seconds have elapsed since its most recent transmission and it has not yet received any reply, server ii will resend the message. This resending repeats every patience[i] seconds until server ii receives its first reply. Once a data server receives any reply, it immediately stops sending messages.

Return the earliest second at which the network becomes idle, meaning there are no messages in transit between any servers.

Constraints:

  • n == patience.length

  • 2≤n≤1052 \leq n \leq 10^5

  • patience[0] =0= 0

  • 1≤1 \leq patience[i] ≤105\leq 10^5 for 1≤i<n1 \leq i < n

  • 1≤1 \leq edges.length ≤min⁡(105,n⋅(n−1)2)\leq \min(10^5, \frac{n \cdot (n - 1)}{2})

  • edges[i].length =2= 2

  • 0≤ui,vi<n0 \leq u_i, v_i < n

  • ui≠viu_i \neq v_i

  • There are no duplicate edges.

  • Each server can directly or indirectly reach another server.