Submission #594012

#TimeUsernameProblemLanguageResultExecution timeMemory
594012uroskCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
306 ms30332 KiB
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;
#define maxn 100005
ll n,m;
vector<pll> g[maxn];
vector<ll> dg[maxn];
ll s,t,u,v;
ll d1[maxn];
ll d2[maxn];
ll dpu[maxn];
ll dpv[maxn];
ll dp[maxn];
bool vis[maxn];
vector<ll> b;
void dis(ll* d,ll c){
    fill(d,d+n+1,llinf);
    d[c] = 0;
    priority_queue<pll> q;
    q.push({0,c});
    vector<bool> vis(n+1);
    while(sz(q)){
        ll u = q.top().sc;
        q.pop();
        if(vis[u]) continue;
        vis[u] = 1;
        for(pll p : g[u]){
            ll s = p.fi;
            ll w = p.sc;
            if(d[u]+w<d[s]){
                d[s] = d[u] + w;
                q.push({-d[s],s});
            }
        }
    }
    //cerr<<"source: "<<c<<endl;
    //ceri(d,1,n);
}
void top(ll u){
    vis[u] = 1;
    for(ll s : dg[u]){
        if(vis[s]) continue;
        top(s);
    }
    b.pb(u);
}
int main(){
	daj_mi_malo_vremena
    cin >> n >> m >> s >> t >> u >> v;
    for(ll i = 1;i<=m;i++){
        ll x,y,w; cin >> x >> y >> w;
        g[x].pb({y,w});
        g[y].pb({x,w});
    }
    dis(d1,s);
    dis(d2,t);
    for(ll i = 1;i<=n;i++){
        for(pll p : g[i]){
            ll j = p.fi;
            ll w = p.sc;
            if(d1[i] + w + d2[j]==d1[t]){
                dg[i].pb(j);
            }
        }
    }
    top(s);
    dis(d1,u);
    dis(d2,v);
    fill(dp,dp+n+1,llinf);
    fill(dpv,dpv+n+1,llinf);
    fill(dpu,dpu+n+1,llinf);
    for(ll x : b){
        dp[x] = d1[x] + d2[x];
        dpu[x] = d1[x];
        dpv[x] = d2[x];
        for(pll p : g[x]){
            ll y = p.fi;
            ll w = p.sc;
            dpu[x] = min(dpu[x],dpu[y]);
            dpv[x] = min(dpv[x],dpv[y]);
            dp[x] = min(dp[x],dp[y]);
        }
        dp[x] = min({dp[x],dpu[x]+d2[x],d1[x]+dpv[x]});
    }
    cout<<min(dp[s],d1[v])<<endl;
	return 0;
}
/*
6 6
1 6
1 4
1 2 1
2 3 1
3 5 1
2 4 3
4 5 2
5 6 1
*/

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:93:16: warning: unused variable 'w' [-Wunused-variable]
   93 |             ll w = p.sc;
      |                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...