Submission #889043

#TimeUsernameProblemLanguageResultExecution timeMemory
889043yeediotCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
431 ms34320 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define F first #define S second #define all(x) x.begin(),x.end() #define pii pair<int,int> #define pb push_back #define sz(x) (int)(x.size()) #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) #define vi vector<int> #define vp vector<pii> #define vvi vector<vi> #define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) void __print(int x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef local void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);} #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else void setio(){} #define debug(x...) #endif void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } struct line{ int a,b; int operator()(const int x)const{ return a*x+b; } }; bool check(line l1,line l2,line l3){ return (l3.b-l2.b)*(l1.a-l2.a)<=(l2.b-l1.b)*(l2.a-l3.a); } const int mxn=1e5+5; vector<pii>adj[mxn]; int d[4][mxn]; int dp[2][mxn]; bool vis[mxn]; void dij(int st,int arr[]){ fill(vis,vis+mxn,false); priority_queue<pii,vector<pii>,greater<pii>>pq; pq.push({0,st}); while(sz(pq)){ auto [dis,v]=pq.top(); pq.pop(); if(!vis[v]){ arr[v]=dis; vis[v]=1; for(auto &u:adj[v]){ pq.push({dis+u.S,u.F}); } } } } int ans; void dij2(int st,int ed,int arr[]){ fill(vis,vis+mxn,false); fill(dp[0],dp[0]+mxn,1e18); fill(dp[1],dp[1]+mxn,1e18); priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>>pq; pq.push({0,{st,0}}); dp[0][0]=dp[1][0]=1e18; while(sz(pq)){ int dis=pq.top().F; int v=pq.top().S.F; int pa=pq.top().S.S; pq.pop(); if(!vis[v]){ vis[v]=1; arr[v]=dis; dp[0][v]=min(d[0][v],dp[0][pa]); dp[1][v]=min(d[1][v],dp[1][pa]); for(auto u:adj[v]){ pq.push({u.S+dis,{u.F,v}}); } } else if(dis==arr[v]){ if(min(d[0][v],dp[0][pa])+min(d[1][v],dp[1][pa])<=dp[0][v]+dp[1][v]){ dp[0][v]=min(d[0][v],dp[0][pa]); dp[1][v]=min(d[1][v],dp[1][pa]); } } debug(v,dp[0][v]+dp[1][v]); } chmin(ans,dp[0][ed]+dp[1][ed]); } signed main(){ setio(); ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int n,m,s,t,u,v; cin>>n>>m>>s>>t>>u>>v; for(int i=0;i<m;i++){ int a,b,c; cin>>a>>b>>c; adj[a].pb({b,c}); adj[b].pb({a,c}); } dij(u,d[0]); dij(v,d[1]); ans=d[0][v]; for(int i=1;i<=n;i++){ debug(d[0][i]); } dij2(s,t,d[2]); dij2(t,s,d[3]); cout<<ans<<'\n'; } /* input: [node,dp[0][node]+dp[1][node]] = [6, 46] [node,dp[0][node]+dp[1][node]] = [3, 22] [node,dp[0][node]+dp[1][node]] = [1, 21] [node,dp[0][node]+dp[1][node]] = [8, 20] [node,dp[0][node]+dp[1][node]] = [4, 21] [node,dp[0][node]+dp[1][node]] = [3, 22] [node,dp[0][node]+dp[1][node]] = [9, 19] [node,dp[0][node]+dp[1][node]] = [1, 21] [node,dp[0][node]+dp[1][node]] = [1, 21] [node,dp[0][node]+dp[1][node]] = [8, 20] [node,dp[0][node]+dp[1][node]] = [5, 27] [node,dp[0][node]+dp[1][node]] = [2, 15] [node,dp[0][node]+dp[1][node]] = [2, 15] [node,dp[0][node]+dp[1][node]] = [2, 15] [node,dp[0][node]+dp[1][node]] = [5, 27] [node,dp[0][node]+dp[1][node]] = [6, 46] [node,dp[0][node]+dp[1][node]] = [9, 19] [node,dp[0][node]+dp[1][node]] = [8, 20] [node,dp[0][node]+dp[1][node]] = [4, 21] [node,dp[0][node]+dp[1][node]] = [3, 22] [node,dp[0][node]+dp[1][node]] = [1, 21] [node,dp[0][node]+dp[1][node]] = [10, 21] [node,dp[0][node]+dp[1][node]] = [3, 22] [node,dp[0][node]+dp[1][node]] = [10, 21] [node,dp[0][node]+dp[1][node]] = [7, 12] [node,dp[0][node]+dp[1][node]] = [7, 3] [node,dp[0][node]+dp[1][node]] = [6, 46] [node,dp[0][node]+dp[1][node]] = [1, 21] [node,dp[0][node]+dp[1][node]] = [2, 15] [node,dp[0][node]+dp[1][node]] = [8, 20] [node,dp[0][node]+dp[1][node]] = [5, 27] [node,dp[0][node]+dp[1][node]] = [8, 21] [node,dp[0][node]+dp[1][node]] = [9, 19] [node,dp[0][node]+dp[1][node]] = [1, 21] [node,dp[0][node]+dp[1][node]] = [8, 21] [node,dp[0][node]+dp[1][node]] = [8, 21] [node,dp[0][node]+dp[1][node]] = [4, 20] [node,dp[0][node]+dp[1][node]] = [3, 20] [node,dp[0][node]+dp[1][node]] = [1, 21] [node,dp[0][node]+dp[1][node]] = [1, 21] [node,dp[0][node]+dp[1][node]] = [2, 12] [node,dp[0][node]+dp[1][node]] = [2, 12] [node,dp[0][node]+dp[1][node]] = [2, 12] [node,dp[0][node]+dp[1][node]] = [5, 16] [node,dp[0][node]+dp[1][node]] = [6, 20] [node,dp[0][node]+dp[1][node]] = [3, 20] [node,dp[0][node]+dp[1][node]] = [10, 21] [node,dp[0][node]+dp[1][node]] = [9, 19] [node,dp[0][node]+dp[1][node]] = [4, 20] [node,dp[0][node]+dp[1][node]] = [3, 20] [node,dp[0][node]+dp[1][node]] = [8, 21] [node,dp[0][node]+dp[1][node]] = [10, 21] [node,dp[0][node]+dp[1][node]] = [7, 0] [node,dp[0][node]+dp[1][node]] = [1, 21] [node,dp[0][node]+dp[1][node]] = [7, 0] [node,dp[0][node]+dp[1][node]] = [3, 20] [node,dp[0][node]+dp[1][node]] = [6, 20] [node,dp[0][node]+dp[1][node]] = [1, 21] [node,dp[0][node]+dp[1][node]] = [5, 16] [node,dp[0][node]+dp[1][node]] = [8, 21] [node,dp[0][node]+dp[1][node]] = [2, 12] [node,dp[0][node]+dp[1][node]] = [5, 16] */

Compilation message (stderr)

commuter_pass.cpp: In function 'void dij(long long int, long long int*)':
commuter_pass.cpp:62:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   62 |         auto [dis,v]=pq.top();
      |              ^
commuter_pass.cpp: In function 'void setIO(std::string)':
commuter_pass.cpp:40:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:41:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     freopen((s + ".out").c_str(), "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...