Advertisement
jeff69

Untitled

Sep 30th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef long double ld;
  5. int n;
  6. const int MX=5e3+4;
  7. struct node
  8. {
  9. int node;
  10. ll dis;
  11. int num;
  12. };
  13. int t,k;
  14. vector<pair<int,int> > adj[MX];
  15. priority_queue<node> pq;
  16. bool operator <(const node &x,const node &y)
  17. {
  18. if(x.num<y.num)return 1;
  19. if(x.dis>y.dis)return 1;
  20.  
  21.  
  22. return 0;
  23. }
  24.  
  25.  
  26. pair<int,ll> dp[MX];
  27. int ans;
  28. int opt[MX];
  29. pair<int,ll> solve(int x)
  30. {
  31. pair<int,ll> ans={0,0};
  32.  
  33. if(dp[x].first!=-1)return dp[x];
  34. if(adj[x].size()==0)
  35. if(x!=n)return {-1e5,-1e5};
  36. int oo=0;
  37. for(auto u :adj[x])
  38. {
  39. auto v= solve(u.first);
  40. v.first++;
  41. v.second += u.second;
  42. if(v.second>t)continue;
  43. if(v>ans)oo=u.first;
  44. ans=max(ans,v);
  45. }
  46. opt[x]=oo;
  47. return dp[x]=ans;
  48. }
  49. int main()
  50. {
  51. cin>>n>>k>>t;
  52. for(int i=0;i<MX;i++)dp[i].first=dp[i].second=-1;
  53. for(int i=0;i<k;i++)
  54. {
  55. int x,y,z;
  56. scanf("%d%d%d",&x,&y,&z);
  57. adj[x].push_back({y,z});
  58. }
  59.  
  60. ans=solve(1).first+1;
  61. cout<<ans<<endl;
  62. int x=1;
  63. while(ans--)
  64. {
  65. cout<<x<<' ';
  66. x=opt[x];
  67. if(x==0)return 0;
  68. }
  69. /* pq.push({1,0,0});
  70. int ans=0;
  71. node xx;
  72. while(!pq.empty())
  73. {
  74. xx=pq.top();
  75. int x=xx.node;
  76. int y=xx.dis;
  77. int nu=xx.num;
  78. // cout<<x<<endl;
  79. pq.pop();
  80. if (y>t)continue;
  81. if(x==n)break;
  82. if(vis[xx])continue;
  83. vis[xx]=1;
  84.  
  85.  
  86.  
  87.  
  88. for(auto u : adj[x])
  89. {
  90. pq.push({u.first,y+u.second,nu+1});
  91. pa[{u.first,y+u.second,nu+1}]=xx;
  92. }
  93. }
  94. cout<<ans+1<<endl;
  95. for(int i=0;i<=ans;i++)
  96. {
  97. int ret=xx.node;
  98. cout<<ret;
  99. xx=pa[xx];
  100. if(xx.node==0)break;
  101. }*/
  102. return 0;
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement