Tap here to switch tabs
Problem
Submissions

Problem: Minimum Distance Excluding One Maximum Weighted Edge

Try to solve the Minimum Distance Excluding One Maximum Weighted Edge problem.

Statement

You are given an integer n representing the number of nodes in a connected undirected graph, with nodes labeled from 00 to n −1- 1. You are also given a 22D integer array edges, where edges[i] = [u_i, v_i, w_i] denotes an undirected edge connecting node u_i and node v_i with weight w_i.

The cost of a path between node 00 and node n −1- 1 is defined as the sum of all edge weights along that path, excluding the weight of exactly one edge with the maximum weight on that path.

Return the minimum possible cost of a path from node 00 to node n −1- 1.

Constraints:

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

  • n −1≤- 1 \leq edges.length ≤109\leq 10^9

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

  • 0≤0 \leq u_i << v_i << n

  • [u_i, v_i] != [u_j, v_j] for all i≠ji \neq j

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

  • The graph is connected.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Distance Excluding One Maximum Weighted Edge

Try to solve the Minimum Distance Excluding One Maximum Weighted Edge problem.

Statement

You are given an integer n representing the number of nodes in a connected undirected graph, with nodes labeled from 00 to n −1- 1. You are also given a 22D integer array edges, where edges[i] = [u_i, v_i, w_i] denotes an undirected edge connecting node u_i and node v_i with weight w_i.

The cost of a path between node 00 and node n −1- 1 is defined as the sum of all edge weights along that path, excluding the weight of exactly one edge with the maximum weight on that path.

Return the minimum possible cost of a path from node 00 to node n −1- 1.

Constraints:

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

  • n −1≤- 1 \leq edges.length ≤109\leq 10^9

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

  • 0≤0 \leq u_i << v_i << n

  • [u_i, v_i] != [u_j, v_j] for all i≠ji \neq j

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

  • The graph is connected.