File tree 1 file changed +62
-0
lines changed
1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Alhamdulillah
2
+
3
+ #include < bits/stdc++.h>
4
+ using namespace std ;
5
+ #define ll long long
6
+ #define eb emplace_back
7
+
8
+ #define forr (i, a, b ) for (ll i = a; i < b; i++)
9
+ #define fast \
10
+ ios_base::sync_with_stdio (0 ); \
11
+ cin.tie(0 ); \
12
+ cout.tie(0 );
13
+
14
+ const ll mod = 1e9 + 7 ;
15
+
16
+ vector<vector<ll>> adj_list;
17
+ vector<ll> vis, topoPath;
18
+
19
+ void dfs (ll curr) {
20
+ vis[curr] = 1 ;
21
+
22
+ for (ll neigh : adj_list[curr]) {
23
+ if (!vis[neigh]) {
24
+ dfs (neigh);
25
+ }
26
+ }
27
+ topoPath.emplace_back (curr);
28
+ }
29
+
30
+ int main () {
31
+ fast;
32
+ ll n, m, x, y, i;
33
+ cin >> n >> m;
34
+
35
+ vector<ll> par (n + 1 ), dist (n + 1 ), ans;
36
+ adj_list.resize (n + 1 );
37
+ vis.resize (n + 1 , 0 );
38
+
39
+ for (i = 1 ; i <= m; i++) {
40
+ cin >> x >> y;
41
+ adj_list[x].eb (y);
42
+ }
43
+
44
+ dfs (1 );
45
+
46
+ if (vis[n] == 0 ) {
47
+ cout << " 0\n " ;
48
+ return 0 ;
49
+ }
50
+
51
+ reverse (topoPath.begin (), topoPath.end ());
52
+
53
+ dist[topoPath[0 ]] = 1 ;
54
+
55
+ for (auto i : topoPath) {
56
+ for (auto x : adj_list[i]) {
57
+ dist[x] = (dist[x] + dist[i]) % mod;
58
+ }
59
+ }
60
+
61
+ cout << dist[n];
62
+ }
You can’t perform that action at this time.
0 commit comments