Submission #1016366

#TimeUsernameProblemLanguageResultExecution timeMemory
1016366sun2305Commuter Pass (JOI18_commuter_pass)C++14
0 / 100
4 ms6136 KiB
#include <bits/stdc++.h> #define ll long long #define se second #define fi first #define pll pair<ll,ll> #define maxn 100005 using namespace std; ll n,m,s,t,u,v,du[maxn],dv[maxn],ans; vector<pll> g[maxn]; void djk1(ll st,ll d[]){ priority_queue<pll,vector<pll>,greater<pll>> q; bool vs[maxn]; 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>,vector<pair<ll,pll>>,greater<pair<ll,pll>>> q; bool vs[maxn]; ll ds[maxn],dp[3][maxn]; 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]= LLONG_MAX/2; 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() { freopen("PathLib.Inp","r",stdin); freopen("PathLib.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:60:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   freopen("PathLib.Inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:61:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   freopen("PathLib.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...