Tap here to switch tabs
Problem
Submissions

Problem: Reachable Nodes In Subdivided Graph

Try to solve the Reachable Nodes In Subdivided Graph problem.

Statement

You are given an undirected graph with nn nodes labeled from 00 to n−1n - 1, and an array edges where edges[i] = [u_i, v_i, cnt_i] indicates that there is an edge between nodes u_i and v_i subdivided into cnt_i new nodes.

Subdividing an edge means replacing the edge between u_i and v_i with a chain of cnt_i new intermediate nodes, resulting in cnt_i + 1 new edges.

Starting at node 00, you can move to any adjacent node by traveling along an edge. Each step from one node to an adjacent node counts as 11 move.

Return the total number of nodes (both original nodes and newly subdivided nodes) that can be reached from node 00 in at most maxMoves moves.

Constraints:

  • 0≤0 \leq edges.length ≤min⁡(n⋅(n−1)/2,104)\leq \min(n \cdot (n - 1) / 2, 10^4)

  • edges[i].length =3= 3

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

  • There are no multiple edges in the graph.

  • 0≤cnti≤1040 \leq cnt_i \leq 10^4

  • 0≤0 \leq maxMoves ≤109\leq 10^9

  • 1≤n≤30001 \leq n \leq 3000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Reachable Nodes In Subdivided Graph

Try to solve the Reachable Nodes In Subdivided Graph problem.

Statement

You are given an undirected graph with nn nodes labeled from 00 to n−1n - 1, and an array edges where edges[i] = [u_i, v_i, cnt_i] indicates that there is an edge between nodes u_i and v_i subdivided into cnt_i new nodes.

Subdividing an edge means replacing the edge between u_i and v_i with a chain of cnt_i new intermediate nodes, resulting in cnt_i + 1 new edges.

Starting at node 00, you can move to any adjacent node by traveling along an edge. Each step from one node to an adjacent node counts as 11 move.

Return the total number of nodes (both original nodes and newly subdivided nodes) that can be reached from node 00 in at most maxMoves moves.

Constraints:

  • 0≤0 \leq edges.length ≤min⁡(n⋅(n−1)/2,104)\leq \min(n \cdot (n - 1) / 2, 10^4)

  • edges[i].length =3= 3

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

  • There are no multiple edges in the graph.

  • 0≤cnti≤1040 \leq cnt_i \leq 10^4

  • 0≤0 \leq maxMoves ≤109\leq 10^9

  • 1≤n≤30001 \leq n \leq 3000