Submission #937255

#TimeUsernameProblemLanguageResultExecution timeMemory
937255Marco_EscandonCommuter Pass (JOI18_commuter_pass)C++11
100 / 100
400 ms36076 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define x first #define y second vector<vector<ll>> v(5,vector<ll>(100001,1e16)); vector<vector<pair<ll,ll>>>G1(100001); vector<vector<ll>>G2(100001); void dijkstra(ll pl, ll node) { priority_queue<pair<ll,ll>> q; q.push({0,node}); while(!q.empty()) { pair<ll,ll> a=q.top();q.pop(); if(v[pl][a.y]==1e16) { v[pl][a.y]=-a.x; for(auto i:G1[a.y]) if(v[pl][i.x]==1e16) q.push({a.x-i.y,i.x}); } } } vector<pair<ll,pair<ll,ll>>> dp(100001,{-1,{0,0}}); pair<ll,pair<ll,ll>> dfs(ll node, ll padre) { if(dp[node].first!=-1) return dp[node]; pair<ll,pair<ll,ll>> sol={v[2][node]+v[3][node],{v[2][node],v[3][node]}}; for(auto i:G2[node]) { if(i!=padre) { pair<ll,pair<ll,ll>> temp=dfs(i,node); sol.x=min(sol.x,temp.x); sol.x=min(sol.x,v[2][node]+temp.y.y); sol.x=min(sol.x,v[3][node]+temp.y.x); sol.y.x=min(sol.y.x,temp.y.x); sol.y.y=min(sol.y.y,temp.y.y); } } return dp[node]=sol; } int main() { ll n,m; cin>>n>>m; ll s,t,u,w; cin>>s>>t>>u>>w; for(int i=0; i<m; i++) { ll a,b,c; cin>>a>>b>>c; G1[a].push_back({b,c}); G1[b].push_back({a,c}); } dijkstra(0,s); dijkstra(1,t); dijkstra(2,u); dijkstra(3,w); for(int i=1; i<=n; i++) for(auto j:G1[i]) if(v[0][i]+v[1][j.x]+j.y==v[0][t]) G2[i].push_back(j.x); cout<<min(dfs(s,0).x,v[2][w]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...