Advertisement
jeff69

Untitled

Feb 10th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MX=2e5+6;
  4. int n,m, dp[MX],a,b;
  5. vector<vector<pair<int,int>>>adj;
  6. int solve(int x)
  7. {
  8. int ans=1e9;
  9. if(dp[x]!=-1)return dp[x];
  10. if(x==b)return 0;
  11. for(auto u : adj[x])
  12. {
  13. ans=min(ans,u.second+solve(u.first));
  14. }
  15. return dp[x]=ans;
  16. }
  17. int main()
  18. {
  19. memset(dp,-1,sizeof dp);
  20. scanf("%d%d",&n,&m);
  21. adj.resize(n+3);
  22. for(int i=0;i<m;i++)
  23. {
  24. int x,y,z;
  25. scanf("%d%d%d",&x,&y,&z);
  26. adj[x].push_back({y,z});
  27. }
  28. scanf("%d%d",&a,&b);
  29. cout<<solve(a);
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement