Reach the Queen
Practice
5 (1 votes)
Graph
Tree
Algorithms
Graphs
Topological sort
Problem
63% Success 1131 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

There are \(N\) cities and \(M\) directed roads connecting them. The king is at city \(1\) and his queen is at city \(N\).

He needs to find the number of ways to reach the queen. The cities are connected in a way that they don't form directed cycles.

Input Format:

The first input line has two integers \(N\) and \(M\)
Then there are \(M\) lines describing the roads. Each line has two integers \(a\) and \(b\) i.e there is a directed road from city \(a\) to city \(b\)

Output Format:

 Print the number of ways modulo \(10^9 + 7\)

Constraints:

\(1 \leq N \leq 2*10^5 \\ 1 \leq M \leq 4*10^5 \\ 1 \leq a,b \leq N\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
65 votes
Tags:
AlgorithmsApprovedData StructuresDepth First SearchGraphsMediumOpenSorting
Points:30
12 votes
Tags:
AlgorithmsC++GraphsSorting
Points:30
2 votes
Tags:
Topological SortAlgorithmsGraphs