Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int MX=2e5+6;
- int n,m, dp[MX],a,b;
- vector<vector<pair<int,int>>>adj;
- int solve(int x)
- {
- int ans=1e9;
- if(dp[x]!=-1)return dp[x];
- if(x==b)return 0;
- for(auto u : adj[x])
- {
- ans=min(ans,u.second+solve(u.first));
- }
- return dp[x]=ans;
- }
- int main()
- {
- memset(dp,-1,sizeof dp);
- scanf("%d%d",&n,&m);
- adj.resize(n+3);
- for(int i=0;i<m;i++)
- {
- int x,y,z;
- scanf("%d%d%d",&x,&y,&z);
- adj[x].push_back({y,z});
- }
- scanf("%d%d",&a,&b);
- cout<<solve(a);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement