fork(2) download
  1. /*
  2. Author : Chandan Agrawal
  3. College : Poornima College of Engg. jaipur, Raj
  4. Mail : chandanagrawal23@gmail.com
  5.  
  6.  
  7. " when you are not practicing someone else is ,
  8.  and the day u meet them u will lose "
  9.  
  10. */
  11. #include<bits/stdc++.h>
  12. #include<stdio.h>
  13. using namespace std;
  14.  
  15. #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  16. #define MAX 200050
  17.  
  18. #define ll long long
  19. #define ld long double
  20. #define lli long long int
  21.  
  22. #define pb push_back
  23. #define INF 1000000000000
  24. #define mod 1000000007
  25.  
  26. // trignometric function always give value in Radians only
  27. #define PI acos(-1) //3.1415926535897932384626433832795028
  28. #define dsin(degree) sin(degree*(PI/180.0))
  29. #define dcos(degree) cos(degree*(PI/180.0))
  30. #define dtan(degree) tan(degree*(PI/180.0))
  31.  
  32. #define rsin(radian) sin(radian)
  33. #define rcos(radian) cos(radian)
  34. #define rtan(radian) tan(radian)
  35.  
  36. #define mem0(a) memset(a,0,sizeof(a))
  37. #define mem1(a) memset(a,-1,sizeof(a))
  38. #define memf(a) memset(a,false,sizeof(a))
  39.  
  40. #define loop(i,n) for (lli i = 0; i < n; i++)
  41. #define FOR(i,a,b) for (lli i = a; i < b; i+=1)
  42.  
  43. #define all(v) v.begin(),v.end()
  44. #define rall(v) v.rbegin(),v.rend()
  45. #define sz(x) int(x.size())
  46. #define F first
  47. #define S second
  48.  
  49. #define mii map<lli,lli>
  50. #define mci map<char,lli>
  51. #define vi vector<lli>
  52. #define vbool vector<bool>
  53. #define seti set<lli>
  54. #define pii pair<lli,lli>
  55. #define pcc pair<char,char>
  56.  
  57. #define gcd(a,b) __gcd((a),(b))
  58. #define lcm(a,b) (a/gcd(a,b))*b
  59. #define abs(x) ((x < 0)?-(x):x)
  60.  
  61. #define endl '\n'
  62.  
  63. template <typename T>
  64. void print(T x){cout<<x<<endl;}
  65. template <typename T1, typename T2>
  66. void print2(T1 x,T2 y){cout<<x<<" "<<y<<endl;}
  67. template <typename T1, typename T2,typename T3>
  68. void print3(T1 x, T2 y,T3 z){cout<<x<<" "<<y<<" "<<z<<endl;}
  69.  
  70. #define scanarr(a,n) for(lli i=0;i<n;i++) cin>>a[i];
  71. #define scanvec(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);}
  72.  
  73. #define printarr(a,n) for(lli i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
  74. #define printvec(vec) for(auto xt : vec) cout<<xt<<" "; cout<<"\n";
  75.  
  76. #define FD(N) fixed<<setprecision(N)
  77.  
  78. #define deb(x) cout<<#x<<" "<<x<<endl;
  79.  
  80. // chandan1,2
  81. void chandan1(){int y=1;return;}
  82. void chandan2(){
  83. loop(i,10){
  84. lli x=1;
  85. }
  86. return(chandan1());
  87. }
  88.  
  89. lli dist[MAX];
  90. lli parent[MAX];
  91. int vis[MAX];
  92. vi adj[MAX];
  93.  
  94. void dfs(lli src , lli lvl)
  95. {
  96. vis[src]=1;
  97. dist[src] = lvl;
  98.  
  99. for(auto xt : adj[src])
  100. {
  101. if(!vis[xt])
  102. {
  103. parent[xt] = src;
  104. dfs(xt , lvl+1);
  105. }
  106. else
  107. {
  108. if(dist[xt] < dist[src]+1)
  109. {
  110. dist[xt] = dist[src]+1;
  111. parent[xt] = src;
  112. }
  113. }
  114. }
  115. }
  116.  
  117. int main(){
  118. fastio
  119. lli t=1;
  120. //cin>>t;
  121. chandan2();
  122. while(t--) {
  123.  
  124. lli n,m;
  125.  
  126. cin>>n>>m;
  127.  
  128. loop(i,m)
  129. {
  130. lli x,y;
  131. cin>>x>>y;
  132. adj[x].pb(y);
  133. }
  134. dfs(1,0);
  135.  
  136. if(dist[n]==0)
  137. print("IMPOSSIBLE");
  138. else
  139. {
  140. vi ans;
  141. ans.pb(n);
  142. while(n!=1)
  143. {
  144. n = parent[n];
  145. ans.pb(n);
  146. }
  147.  
  148. reverse(all(ans));
  149. print(sz(ans));
  150. printvec(ans);
  151. }
  152. }
  153. return 0;
  154. }
  155.  
Success #stdin #stdout 0s 8272KB
stdin
5 5
1 2
2 5
1 3
3 4
4 5
stdout
4
1 3 4 5