fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define for1(i,m,n) for(int i=m;i<=n;i++)
  5. #define for0(i,m,n) for(int i=m;i<n;i++)
  6.  
  7. #define int long long
  8. #define el '\n'
  9. #define fi first
  10. #define se second
  11. #define ii pair<int,int>
  12. #define vll(i) i.begin(),i.end()
  13. #define pb push_back
  14.  
  15. const int N=2*1e5;
  16. const int mod=1e9+7;
  17. int n_,m,w,k,s;
  18. int v[111];
  19. unordered_map<int,int>pre;
  20. vector<int> n[111],p;
  21. int dinh_to_so(int x,int y){
  22. return x*(s+1)+y;
  23. }
  24. void so_to_dinh(int p,int &x,int &y){
  25. x=p/(s+1);
  26. y=p%(s+1);
  27. }
  28.  
  29. signed main(){
  30. ios_base::sync_with_stdio(0);
  31. cin.tie(0);
  32. cout.tie(0);
  33. // freopen("bai1.INP","r",stdin);
  34. // freopen("bai1.OUT","w",stdout);
  35.  
  36.  
  37. cin>>n_>>m>>w>>k>>s;
  38. for1(i,1,n_) cin>>v[i];
  39. while(m--){
  40. int x,y;cin>>x>>y;
  41. n[x].pb(y);
  42. n[y].pb(x);
  43. }
  44. queue<int>q;
  45. q.push(dinh_to_so(k,s));
  46. pre[dinh_to_so(k,s)]=-1;
  47. while(!q.empty()){
  48. int x,y;
  49. so_to_dinh(q.front(),x,y);
  50. //cout<<x<<' '<<y<<el;
  51. for(auto u:n[x]){
  52. // cout<<u<<' '<<v[u]<<' '<<y-v[x]<<el;
  53. // cout<<d[u]<<' '<<d[x]+1<<el;
  54. if(v[u]<=y-v[x]){
  55. int next =dinh_to_so(u,y-v[x]);
  56. if(pre.count(next)){
  57. continue;
  58. }
  59. pre[next]=q.front();
  60. q.push(next);
  61. }
  62.  
  63. }
  64. q.pop();
  65. }
  66. int dau=dinh_to_so(w,v[w]);
  67. while(dau!=-1){
  68. // cout<<dau<<el;
  69. int x,y;
  70. so_to_dinh(dau,x,y);
  71. p.pb(x);
  72. dau=pre[dau];
  73. }
  74.  
  75.  
  76. cout<<p.size()<<" ";
  77. for(auto x:p) cout<<x<<' ';
  78.  
  79. return 0;
  80. }
  81.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
1  0