Tap here to switch tabs
Problem
Submissions

Problem: Maximum Path Quality of a Graph

Try to solve the Maximum Path Quality of a Graph problem.

Statement

There is an undirected graph with nn nodes labeled from 00 to n−1n - 1, where node ii has a value given by values[i]. You are provided a 22D integer array edges, where edges[j] = [u_j, v_j, time_j] denotes an undirected edge between node uju_j and node vjv_j that takes timejtime_j time units to traverse. You are also given an integer maxTime.

A valid path is any sequence of nodes that begins at node 00, ends at node 00, and has a total traversal time of at most maxTime. Nodes and edges may be visited multiple times. The quality of a path is defined as the sum of values[i] across all unique nodes visited along the path, meaning the value of each visited node is counted only once.

Return the maximum path quality among all valid paths.

Constraints:

  • n == values.length

  • 1≤n≤10001 \leq n \leq 1000

  • 0≤0 \leq values[i] ≤108\leq 10^8

  • 0≤0 \leq edges.length ≤2000\leq 2000

  • edges[j].length ==3== 3

  • 0≤uj<vj≤n−10 \leq u_j < v_j \leq n - 1

  • 10≤timej≤10010 \leq time_j \leq 100

  • 10≤10 \leq maxTime ≤100\leq 100

  • All the pairs [uj,vj][u_j, v_j] are unique.

  • There are at most 44 edges connected to each node.

  • The graph may not be connected.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Path Quality of a Graph

Try to solve the Maximum Path Quality of a Graph problem.

Statement

There is an undirected graph with nn nodes labeled from 00 to n−1n - 1, where node ii has a value given by values[i]. You are provided a 22D integer array edges, where edges[j] = [u_j, v_j, time_j] denotes an undirected edge between node uju_j and node vjv_j that takes timejtime_j time units to traverse. You are also given an integer maxTime.

A valid path is any sequence of nodes that begins at node 00, ends at node 00, and has a total traversal time of at most maxTime. Nodes and edges may be visited multiple times. The quality of a path is defined as the sum of values[i] across all unique nodes visited along the path, meaning the value of each visited node is counted only once.

Return the maximum path quality among all valid paths.

Constraints:

  • n == values.length

  • 1≤n≤10001 \leq n \leq 1000

  • 0≤0 \leq values[i] ≤108\leq 10^8

  • 0≤0 \leq edges.length ≤2000\leq 2000

  • edges[j].length ==3== 3

  • 0≤uj<vj≤n−10 \leq u_j < v_j \leq n - 1

  • 10≤timej≤10010 \leq time_j \leq 100

  • 10≤10 \leq maxTime ≤100\leq 100

  • All the pairs [uj,vj][u_j, v_j] are unique.

  • There are at most 44 edges connected to each node.

  • The graph may not be connected.