제출 #1033521

#제출 시각아이디문제언어결과실행 시간메모리
1033521LuvidiCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
2068 ms23216 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define fs first #define sc second #define pb push_back const int maxn=1e5; int n,m; vector<pll> adj[maxn+1]; ll ds[maxn+1],dx[maxn+1],dy[maxn+1],ans=1e18; void dj(int v,ll dist[]){ for(int i=1;i<=n;i++)dist[i]=1e18; bool vis[n+1]; memset(vis,0,sizeof(vis)); priority_queue<pll> pq; dist[v]=0; pq.push({0,v}); while(!pq.empty()){ ll i=pq.top().sc; pq.pop(); if(vis[i])continue; vis[i]=1; for(auto[u,w]:adj[i])if(!vis[u]){ dist[u]=min(dist[u],dist[i]+w); pq.push({-dist[u],u}); } } } ll f1(int v){ ll x=dy[v]; for(auto[u,w]:adj[v]){ if(ds[v]==ds[u]+w){ ll y=f1(u); x=min(x,y); ans=min(ans,dx[v]+y); } } return x; } ll f2(int v){ ll x=dx[v]; for(auto[u,w]:adj[v]){ if(ds[v]==ds[u]+w){ ll y=f2(u); x=min(x,y); ans=min(ans,dy[v]+y); } } return x; } void solve() { cin>>n>>m; int s,t,x,y; cin>>s>>t>>x>>y; while(m--){ int u,v,w; cin>>u>>v>>w; adj[u].pb({v,w}); adj[v].pb({u,w}); } dj(s,ds); dj(x,dx); dj(y,dy); f1(t); f2(t); cout<<min(ans,dx[y]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...