Advertisement
a53

shell

a53
Nov 21st, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <cassert>
  5.  
  6. #define MOD 1000000007LL
  7.  
  8. using namespace std;
  9.  
  10. int n, m, p;
  11. vector <int> g[1000010];
  12. int dp[1000010], v[1000010];
  13. long long nr[1000010];
  14.  
  15. void dfs (int nod)
  16. {
  17. if (nod == n)
  18. {
  19. dp[nod] = 1;
  20. nr[nod] = 1LL;
  21.  
  22. if (nod == v[ p - dp[nod] + 1 ]) ++dp[nod];
  23. return;
  24. }
  25.  
  26. for (auto &it : g[nod])
  27. {
  28. if (dp[it] == 0) dfs (it);
  29.  
  30. if (dp[it] > dp[nod]) dp[nod] = dp[it], nr[nod] = nr[it];
  31. else if (dp[it] == dp[nod]) nr[nod] += nr[it];
  32.  
  33. nr[nod] %= MOD;
  34. }
  35.  
  36. if (nod == v[ p - dp[nod] + 1 ]) ++dp[nod];
  37. }
  38.  
  39. int main ()
  40. {
  41. // freopen ("input", "r", stdin);
  42. // freopen ("output1", "w", stdout);
  43.  
  44. scanf ("%d %d %d", &n, &m, &p);
  45.  
  46. assert (1 <= n && n <= 1000000);
  47. // assert (1 <= m && m <= 1000000);
  48. assert (1 <= p && p <= 1000000);
  49.  
  50. for (int i = 1; i <= p; ++i)
  51. {
  52. scanf ("%d", &v[i]);
  53. assert (1 <= v[i] && v[i] <= n);
  54. }
  55.  
  56. for (int i = 1; i <= m; ++i)
  57. {
  58. int x, y;
  59. scanf ("%d %d", &x, &y);
  60.  
  61. assert (1 <= x && x <= n);
  62. assert (1 <= y && y <= n);
  63. assert (x != y);
  64.  
  65. g[x].push_back (y);
  66. }
  67.  
  68. dfs (1);
  69.  
  70. printf ("%lld\n", nr[1]);
  71.  
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement