Tap here to switch tabs
Problem
Submissions

Problem: Number of Restricted Paths From First to Last Node

Try to solve the Number of Restricted Paths From First to Last Node problem.

Statement

There is an undirected, connected, weighted graph with nn nodes labeled from 11 to nn. You are given the integer n and an array edges, where each edges[i] = [ui,vi,weighti][u_i, v_i, weight_i] denotes a bidirectional edge between node uiu_i and node viv_i with a weight of weightiweight_i.

Let distanceToLastNode(x) be the shortest distance from node xx to node nn.

A path from node 11 to node nn formed by a sequence of nodes z1,z2,z3,…,zkz_1, z_2, z_3, \dots, z_k (where z1=1z_1 = 1 and zk=nz_k = n) is defined as a restricted path if distanceToLastNode(ziz_i) >> distanceToLastNode(zi+1z_{i+1}) for all 1≤i<k1 \le i < k.

Return the number of restricted paths from node 11 to node nn. Since the answer can be large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \le n ≤2×104\le 2 \times 10^4

  • n −1≤- 1 \le edges.length ≤4×104\le 4 \times 10^4

  • edges[i].length =3= 3

  • 1≤1 \le u_i, v_i ≤\le n

  • u_i ≠\neq v_i

  • 1≤1 \le weight_i ≤105\le 10^5

  • There is at most one edge between any two nodes.

  • There is at least one path between any two nodes.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Restricted Paths From First to Last Node

Try to solve the Number of Restricted Paths From First to Last Node problem.

Statement

There is an undirected, connected, weighted graph with nn nodes labeled from 11 to nn. You are given the integer n and an array edges, where each edges[i] = [ui,vi,weighti][u_i, v_i, weight_i] denotes a bidirectional edge between node uiu_i and node viv_i with a weight of weightiweight_i.

Let distanceToLastNode(x) be the shortest distance from node xx to node nn.

A path from node 11 to node nn formed by a sequence of nodes z1,z2,z3,…,zkz_1, z_2, z_3, \dots, z_k (where z1=1z_1 = 1 and zk=nz_k = n) is defined as a restricted path if distanceToLastNode(ziz_i) >> distanceToLastNode(zi+1z_{i+1}) for all 1≤i<k1 \le i < k.

Return the number of restricted paths from node 11 to node nn. Since the answer can be large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \le n ≤2×104\le 2 \times 10^4

  • n −1≤- 1 \le edges.length ≤4×104\le 4 \times 10^4

  • edges[i].length =3= 3

  • 1≤1 \le u_i, v_i ≤\le n

  • u_i ≠\neq v_i

  • 1≤1 \le weight_i ≤105\le 10^5

  • There is at most one edge between any two nodes.

  • There is at least one path between any two nodes.