Advertisement
ssrtatarin

Untitled

Feb 7th, 2022
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef __int128 lll;
  5. typedef long long ll;
  6. typedef long double ld;
  7. ll inf = 1e9+1, mod = 1e9 + 7;
  8. const int N = 1e6;
  9. #define all(a) a.begin(),a.end()
  10. #define pb push_back
  11. #define get(a) for(int i = 0; i < (int)a.size(); ++i) cout << a[i]+1 << ' ';
  12. #define SOLVE int t; cin >> t; while(t--) solve();
  13.  
  14. struct mosh
  15. {
  16. int first, second, third;
  17. };
  18.  
  19.  
  20. bool compare2(int a, int b){
  21. return a > b;
  22. }
  23. bool compare(mosh a, mosh b){
  24. if(a.first!= b.first) return a.first > b.first;
  25. else if(a.first == b.first && a.second!= b.second) return a.second < b.second;
  26. else return a.third < b.third;
  27.  
  28. }
  29.  
  30. struct point{
  31. ll first, type;
  32. };
  33.  
  34. bool compare3(point a, point b){
  35. if(a.type == b.type) return a.first < b.first;
  36. else return a.type > b.type;
  37. }
  38. int gcd(int a , int b)
  39. {
  40. if(b==0) return a;
  41. a%=b;
  42. return gcd(b,a);
  43. }
  44. vector<int>g[N];
  45. int pr[N];
  46. void solve(){
  47. int n, m;
  48. cin >> n >> m;
  49. vector<int>dist(n, -1);
  50. for(int i = 0; i < m; ++i){
  51. int a, b;
  52. cin >> a >> b;
  53. --a;
  54. --b;
  55. g[a].pb(b);
  56.  
  57. }
  58. int s, t;
  59.  
  60. cin >> s >> t;
  61. cout << s << '\n';
  62.  
  63. --s;
  64. --t;
  65.  
  66. queue<int>q;
  67. q.push(s);
  68. dist[s] = 0;
  69. while(!q.empty()){
  70. int v = q.front();
  71. q.pop();
  72. for(int to : g[v]){
  73. if(dist[to] == -1){
  74. dist[to] = dist[v] + 1;
  75. q.push(to);
  76. pr[to] = v;
  77. }
  78. }
  79. }
  80. int j = t;
  81. vector<int>ans;
  82. while(j){
  83. ans.pb(j);
  84. j = pr[j];
  85. }
  86. cout << dist[t] << '\n';
  87. cout << s << ' ' << '\n';
  88. reverse(all(ans));
  89.  
  90. get(ans);
  91.  
  92.  
  93. }
  94.  
  95.  
  96. int main() {
  97. #ifdef anime
  98.  
  99. freopen("input1.txt", "r", stdin);
  100. freopen("output1.txt", "w", stdout);
  101. #endif
  102. srand(time(nullptr));
  103. ios_base::sync_with_stdio(false);
  104. cin.tie(nullptr);
  105. cout.tie(nullptr);
  106. solve();
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement