제출 #1268799

#제출 시각아이디문제언어결과실행 시간메모리
1268799bhnmCommuter Pass (JOI18_commuter_pass)C++20
15 / 100
2095 ms27028 KiB
#include<bits/stdc++.h> #define ll long long #define pll pair<long long,long long> using namespace std; const ll maxn = 2e5 + 5; const ll mod = 1e9 + 7; const ll base = 13; const ll inf = 1e14; ll n,m,x,y,z,s,t,u,v; vector<pll>a[maxn]; ll dist[maxn][5]; ll ans; ll best[maxn][5]; priority_queue<pll,vector<pll>,greater<pll>>pe; void dijk(ll st,ll type) { for(ll i = 1;i<=n;i++) { dist[i][type] = inf; } dist[st][type] = 0; pe.push({0,st}); while(!pe.empty()) { ll u = pe.top().second; ll cur = pe.top().first; pe.pop(); if(dist[u][type] < cur) { continue; } for(pll v : a[u]) { if(dist[v.first][type] > dist[u][type] + v.second) { dist[v.first][type] = dist[u][type] + v.second; pe.push({dist[v.first][type],v.first}); } } } } void dfs(ll u) { best[u][2] = dist[u][2]; best[u][3] = dist[u][3]; for(auto [v,w] : a[u]) { if(dist[v][1] + w == dist[u][1]) { dfs(v); best[u][2] = min(best[u][2],best[v][2]); best[u][3] = min(best[u][3],best[v][3]); } } ans = min(ans,min(best[u][2] + dist[u][3],best[u][3] + dist[u][2])); } void solve() { cin>>n>>m>>s>>t>>u>>v; for(ll i = 1;i<=m;++i) { cin>>x>>y>>z; a[x].push_back({y,z}); a[y].push_back({x,z}); } dijk(s,1); dijk(u,2); dijk(v,3); ans = dist[u][3]; dfs(t); cout<<ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("BUS.INP","r",stdin); //freopen("BUS.OUT","w",stdout); ll t = 1; //cin>>t; while(t--) { solve(); } 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...