제출 #372486

#제출 시각아이디문제언어결과실행 시간메모리
372486iliccmarkoCommuter Pass (JOI18_commuter_pass)C++14
31 / 100
416 ms26224 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define INF 1000000000 #define LINF 10000000000000000LL #define pb push_back #define all(x) x.begin(), x.end() #define len(s) (int)s.size() #define test_case { int t; cin>>t; while(t--)solve(); } #define single_case solve(); #define line cerr<<"----------"<<endl; #define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); } #define mod 1000000007LL const int N = 2e5 + 5; vector<pair<ll, ll> > g[N]; ll ds[N], dt[N], du[N], dv[N]; ll n, m, s, t, u, v; int vidjen[N]; void dijkstra(ll src, ll dis[]) { for(int i = 0;i<N;i++) dis[i] = LINF, vidjen[i] = 0; priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > pq; dis[src] = 0; pq.push(make_pair(0, src)); while(len(pq)) { ll u = pq.top().second; pq.pop(); if(vidjen[u]) continue; vidjen[u] = 1; for(auto x : g[u]) { ll v = x.first; ll c = x.second; if(dis[v]>dis[u]+c) { dis[v] = dis[u] + c; pq.push(make_pair(dis[v], v)); } } } } void dijkstramod(ll src, ll dis[]) { for(int i = 0;i<N;i++) dis[i] = LINF, vidjen[i] = 0; priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > pq; dis[src] = 0; pq.push(make_pair(0, src)); while(len(pq)) { ll u = pq.top().second; pq.pop(); if(vidjen[u]) continue; vidjen[u] = 1; for(auto x : g[u]) { ll v = x.first; ll c = x.second; ll k = 0; if(ds[u]+c+dt[v]!=ds[t]&&ds[v]+c+dt[u]!=ds[t]) k = c; if(dis[v]>dis[u]+k) { dis[v] = dis[u] + k; pq.push(make_pair(dis[v], v)); } } } } int main() { ios cin>>n>>m>>s>>t>>u>>v; for(int i = 0;i<m;i++) { ll a, b, c; cin>>a>>b>>c; g[a].pb(make_pair(b, c)); g[b].pb(make_pair(a, c)); } dijkstra(s, ds); dijkstra(t, dt); dijkstramod(u, du); //cout<<du[v]<<endl; dijkstramod(v, dv); ll res = LINF; for(int i = 1;i<=n;i++) { res = min(res, du[i]+dv[i]); } cout<<res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...