Reach the Queen

5

1 votes
Graph, Tree, Algorithms, Graphs, Topological Sort
Problem

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 109+7

Constraints:

1N21051M41051a,bN

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

There is only 1 way to reach from 1 to 4 i.e 1->2->4

Editor Image

?