제출 #332105

#제출 시각아이디문제언어결과실행 시간메모리
332105soroushCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
500 ms43740 KiB
//* //#pragma GCC optimize("O2") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("avx,avx2,sse,sse2,fma") //*/ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef long double ld; typedef pair<int ,int > pii; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll maxn = 2e5 + 10; const ll mod =1e9+7; const ld PI = acos((ld)-1); #define pb push_back #define endl '\n' #define dokme(x) cout << x , exit(0) #define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define ms(x , y) memset(x , y , sizeof x) ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);} struct tr{ int u , w; tr(int a , int b): u(a) , w(b){} friend bool operator < (tr a , tr b){ if(a.w == b.w)return(a.u < b.u); return(a.w > b.w); } }; int n , m; vector < tr > adj[maxn]; int s , t; int a , b; vector < int > ds , dt; priority_queue < tr > st; bool mark[maxn]; #define insert push #define erase pop void djk(int v, vector < int > &dist){ ms(mark , 0); for(int i = 0 ; i <= n ; i ++) dist.pb(1e18); dist[v] = 0; st.insert({v , dist[v]}); while(!st.empty()){ auto vw = (st.top()); auto v = vw.u; st.erase(); if(mark[v])continue; mark[v] = 1; for(auto uw : adj[v]) if(dist[uw.u] > dist[v] + uw.w) dist[uw.u] = dist[v] + uw.w, st.insert({uw.u , dist[uw.u]}); } } vector < int > du , dv; bool sp(int u , int v , int w){ return((ds[u] + dt[v] + w == ds[t])); } int mn[maxn] , mnr[maxn]; int ans = 1e18; vector < int > in[maxn] , out[maxn]; int d[maxn]; vector < int > topo; void dfs(int v){ topo.pb(v); mark[v] = 1; for(auto u : out[v]){ d[u] -- ; if(d[u] == 0) dfs(u); } } int32_t main(){ migmig; cin >> n >> m; cin >> s >> t; cin >> a >> b; for(int i = 1; i <= m ; i ++){ int u , v , w; cin >> u >> v >> w; adj[u].pb({v , w}); adj[v].pb({u , w}); } djk(s , ds); djk(t , dt); djk(a , du); djk(b , dv); for(int v = 1 ; v <= n ; v ++){ for(auto uw : adj[v]){ auto u = uw.u; auto w = uw.w; if(sp(v , u , w))in[u].pb(v) , out[v].pb(u) , d[u] ++ ; } } ms(mark , 0); for(int i = 1; i <= n ; i ++)if(d[i] == 0 and !mark[i])dfs(i); for(int i = 1; i <= n ; i ++)mn[i] = 1e18 , mnr[i] = 1e18; for(auto v : topo){ mn[v] = du[v]; for(auto u : in[v]) mn[v] = min(mn[v] , mn[u]); } reverse(topo.begin() , topo.end()); for(auto v : topo){ mnr[v] = du[v]; for(auto u : out[v]) mnr[v] = min(mnr[v] , mnr[u]); } for(int i = 1 ; i <= n ; i ++)mn[i] = min(mn[i] , mnr[i]); for(int i = 1 ; i <= n ; i ++) ans = min(ans , dv[i] + mn[i]); cout << ans; return(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...