Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct DATA{
- int i;
- long long w;
- long long maxx;
- bool operator <(const DATA & d2) const{
- return w < d2.w;
- }
- };
- vector<pair<int,long long>>g[100100];
- priority_queue<DATA>pq;
- long long dis[100100];
- pair<int,long long> from[100100];
- int main(){
- int n,m,u,v,s,t;
- long long w,ans=0;
- scanf(" %d %d",&n,&m);
- scanf(" %d %d",&s,&t);
- for(int i = 1;i<=m;i++){
- scanf(" %d %d %lld",&u,&v,&w);
- ans += w;
- g[u].push_back({v,w});
- g[v].push_back({u,w});
- }
- for(int i = 0;i<=n;i++) dis[i] = 1e9;
- dis[s] = 0;
- pq.push({s,(long long)0,(long long)0});
- while(!pq.empty()){
- DATA f = pq.top();
- pq.pop();
- //cout << f.i << " " << f.w << " " << f.maxx <<endl;
- for(auto x : g[f.i]){
- int to = x.first;
- w = x.second;
- //cout << "to " << to << " " << w << endl;
- if(f.w + w - max(w,f.maxx) < dis[to]){
- dis[to] = f.w + w - max(w,f.maxx);
- pq.push({to,f.w + w,max(f.maxx,w)});
- //cout << "Push " << to << " " << dis[to] << " " << f.w + w - max(w,f.maxx) << endl;
- }
- }
- }
- //cout << dis[t] << endl;
- printf("%lld",ans-dis[t]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement