Submission #917504

#TimeUsernameProblemLanguageResultExecution timeMemory
917504ReLiceCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
988 ms39656 KiB
#include <bits/stdc++.h> #define ll long long #define str string #define ins insert #define ld long double #define pb push_back #define pf push_front #define pof pop_front() #define pob pop_back() #define lb lower_bound #define ub upper_bound #define endl "\n" #define fr first #define sc second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define sz size() #define vll vector<ll> #define bc back() #define arr array #define pll vector<pair<ll,ll>> using namespace std; template <class _T> bool chmin(_T &x, const _T &y){ bool f=0; if (x>y){x=y;f=1;} return f; } template <class _T> bool chmax(_T &x, const _T &y){ bool f=0; if (x<y){x=y;f=1;} return f; } //void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} void start(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const ll inf=1e9; const ll mod=1e9+7; const ll N=2e5+7; const ld eps=1e-9; vector<pll> g(N); ll dp[2][N],d[N],du[N],dv[N],vis[N],ans; void dis(ll s,ll a[]){ memset(vis,0,sizeof(vis)); set<pair<ll,ll>> st; st.ins({0,s}); while(st.sz){ ll c,v; tie(c,v)=*st.begin(); st.erase(st.begin()); if(vis[v])continue; vis[v]=1; a[v]=c; for(auto i : g[v])st.ins({a[v]+i.sc,i.fr}); } } void calc(ll s,ll e){ memset(vis,0,sizeof(vis)); memset(dp,0x3f,sizeof(dp)); set<pair<ll,pair<ll,ll>>> st; st.ins({0,{s,0}}); while(st.sz){ ll c,v,p; pair<ll,ll> pp; tie(c,pp)=*st.begin(); tie(v,p)=pp; st.erase(st.begin()); if(vis[v] && c==d[v]){ if(min(dp[0][p],du[v])+min(dp[1][p],dv[v])<=dp[0][v]+dp[1][v]){ dp[0][v]=min(dp[0][p],du[v]); dp[1][v]=min(dp[1][p],dv[v]); } continue; }else if(vis[v])continue; vis[v]=1; d[v]=c; dp[0][v]=min(dp[0][p],du[v]); dp[1][v]=min(dp[1][p],dv[v]); for(auto i : g[v])st.ins({d[v]+i.sc,{i.fr,v}}); } chmin(ans,dp[0][e]+dp[1][e]); } void solve(){ ll i,j; ll n,m,u,v,s,t; cin>>n>>m>>s>>t>>u>>v; ll a,b,c; for(i=0;i<m;i++){ cin>>a>>b>>c; g[a].pb({b,c}); g[b].pb({a,c}); } //counting du and dv dis(u,du); dis(v,dv); //simple path ans=du[v]; //calculating dp calc(s,t); calc(t,s); cout<<ans<<endl; } signed main(){ //start(); ll t=1; //cin>>t; while(t--) solve(); return 0; } /* */

Compilation message (stderr)

commuter_pass.cpp: In function 'void solve()':
commuter_pass.cpp:88:10: warning: unused variable 'j' [-Wunused-variable]
   88 |     ll i,j;
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...