Submission #1016369

#TimeUsernameProblemLanguageResultExecution timeMemory
1016369sun2305Commuter Pass (JOI18_commuter_pass)C++14
100 / 100
343 ms34748 KiB
#include <bits/stdc++.h> #define ll long long #define se second #define fi first #define pll pair<ll,ll> #define maxn 100005 #define task "XEBUYT" using namespace std; const ll inf=1e18; ll n,m,s,t,u,v,du[maxn],dv[maxn],ans,ds[maxn],dp[3][maxn]; bool vs[maxn]; vector<pll> g[maxn]; void djk1(ll st,ll d[]){ priority_queue<pll> q; fill(vs,vs+maxn,false); q.push({0,st}); while(!q.empty()){ ll node,w; tie(w,node)=q.top(); q.pop(); if(!vs[node]){ vs[node]=true; d[node]=-w; for(pll it:g[node]) q.push({w-it.se,it.fi}); } } } void djk2(ll st, ll ed){ priority_queue<pair<ll,pll>> q; fill(vs,vs+maxn,false); fill(dp[0], dp[0] + 100001, LLONG_MAX / 2); fill(dp[1], dp[1] + 100001, LLONG_MAX / 2); dp[0][0]=dp[1][0]= inf; q.push({0,{st,0}}); while(!q.empty()){ ll w,node,par;pll p; tie(w,p)=q.top(); tie(node,par)=p; q.pop(); if(!vs[node]){ vs[node]=true; ds[node]=-w; dp[0][node]=min(du[node],dp[0][par]); dp[1][node]=min(dv[node],dp[1][par]); for(pll it:g[node]) q.push({w-it.se,{it.fi,node}}); } else if(-w==ds[node] and min(dp[0][par],du[node])+min(dv[node],dp[1][par])<=dp[1][node]+dp[0][node]){ dp[0][node]=min(dp[0][par],du[node]); dp[1][node]=min(dv[node],dp[1][par]); } } ans=min(ans,dp[0][ed]+dp[1][ed]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(task".INP","r")){ freopen(task".INP","r",stdin); freopen(task".OUT","w",stdout); } cin>>n>>m>>s>>t>>u>>v; for(long i=0;i<m;i++){ ll a,b,c; cin>>a>>b>>c; g[a].push_back({b,c}); g[b].push_back({a,c}); } djk1(u,du); djk1(v,dv); ans=du[v]; djk2(s,t); djk2(t,s); cout<<ans; return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:71:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     freopen(task".INP","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:72:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     freopen(task".OUT","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...