Tap here to switch tabs
Problem
Submissions

Problem: Minimum Time to Visit Disappearing Nodes

Try to solve the Minimum Time to Visit Disappearing Nodes problem.

Statement

There is an undirected graph with n nodes labeled from 00 to n −1- 1. You are given a 22D integer array edges where edges[i] =[= [ u_i, v_i, length_i ]] represents a bidirectional edge between node u_i and node v_i that takes length_i units of time to traverse.

You are also given an integer array disappear of length n, where disappear[i] represents the time at which node i disappears from the graph. Once a node disappears, it cannot be visited or traversed.

Starting at node 00 at time 00, determine the minimum time needed to reach each node.

Return an array answer of size n, where answer[i] is the minimum time required to visit node i, or −1-1 if node i cannot be visited before it disappears.

Constraints:

  • 1≤1 \leq n ≤5×104\leq 5 \times 10^4

  • 0≤0 \leq edges.length ≤105\leq 10^5

  • edges[i] =[= [ u_i, v_i, length_i ]]

  • 0≤0 \leq u_i, v_i ≤\leq n −1- 1

  • 1≤1 \leq length_i ≤105\leq 10^5

  • disappear.length == n

  • 1≤1 \leq disappear[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Time to Visit Disappearing Nodes

Try to solve the Minimum Time to Visit Disappearing Nodes problem.

Statement

There is an undirected graph with n nodes labeled from 00 to n −1- 1. You are given a 22D integer array edges where edges[i] =[= [ u_i, v_i, length_i ]] represents a bidirectional edge between node u_i and node v_i that takes length_i units of time to traverse.

You are also given an integer array disappear of length n, where disappear[i] represents the time at which node i disappears from the graph. Once a node disappears, it cannot be visited or traversed.

Starting at node 00 at time 00, determine the minimum time needed to reach each node.

Return an array answer of size n, where answer[i] is the minimum time required to visit node i, or −1-1 if node i cannot be visited before it disappears.

Constraints:

  • 1≤1 \leq n ≤5×104\leq 5 \times 10^4

  • 0≤0 \leq edges.length ≤105\leq 10^5

  • edges[i] =[= [ u_i, v_i, length_i ]]

  • 0≤0 \leq u_i, v_i ≤\leq n −1- 1

  • 1≤1 \leq length_i ≤105\leq 10^5

  • disappear.length == n

  • 1≤1 \leq disappear[i] ≤105\leq 10^5