Geeksforgeeks

Error

×

Given a directed graph and two vertices **‘u’** and **‘v’** in it. Find the number of possible walks from **‘u’** to **‘v’** with exactly **k** edges on the walk modulo 10^{9}+7.

**Example 1:**

**Input 1: **graph = {{0,1,1,1},{0,0,0,1},
{0,0,0,1}, {0,0,0,0}}, u = 0, v = 3, k = 2
**Output: **2
**Explanation: **Let source ‘u’ be vertex 0,
destination ‘v’ be 3 and k be 2. The output
should be 2 as there are two walk from 0 to
3 with exactly 2 edges. The walks are {0, 2, 3}
and {0, 1, 3}.

**Your Task:**

You don't need to read or print anything. Your task is to complete the function **MinimumWalk() **which takes graph, u, v and k as input parameter and returns total possible paths from u to v using exactly k edges modulo 10^{9}+7.

**Note: **In graph, if graph[i][j] = 1, it means there is an directed edge from vertex i to j.

**Expected Time Complexity: **O(n^{3})

**Expected Space Complexity: **O(n^{3})

**Constraints:**

1 ≤ n ≤ 50

1 ≤ k ≤ n

0 ≤ u, v ≤ n-1

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Possible paths

...