fork download
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. long dp[1005][10];
  9. vector<int> g[1005];
  10.  
  11. int main() {
  12. ios::sync_with_stdio(0);
  13. int n, x, y, t, m, u, v;
  14. cin >> n >> x >> y >> t >> m;
  15. for (int i = 0; i < m; ++i) {
  16. cin >> u >> v;
  17. g[u].push_back(v);
  18. g[v].push_back(u);
  19. }
  20. dp[x][0] = 1;
  21. for (int time = 0; time < t; ++time) {
  22. for (int u = 0; u < n; ++u) {
  23. if (!dp[u][time])
  24. continue;
  25. for (int v : g[u]) {
  26. dp[v][time+1] += dp[u][time];
  27. }
  28. }
  29. }
  30. if (!dp[y][t])
  31. cout << "not possible" << endl;
  32. else
  33. cout << dp[y][t] << endl;
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5480KB
stdin
3 0 0 2 3
0 1
1 2
2 0
stdout
2