Submission #890819

#TimeUsernameProblemLanguageResultExecution timeMemory
890819ByeWorldCommuter Pass (JOI18_commuter_pass)C++14
16 / 100
406 ms41844 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define bupol __builtin_popcount #define int long long #define ll long long #define ld long double #define fi first #define se second #define pb push_back #define lf (id<<1) #define rg ((id<<1)|1) #define md ((l+r)>>1) using namespace std; const int MAXN = 2e5+5; const int LOG = 20; const int MOD = 1e9+7; const int SQRT = 520; const int INF = 1e18; typedef pair<int,int> pii; typedef pair<int,pii> ipii; int n, m; int s, t, x, y; int u[MAXN], v[MAXN], c[MAXN]; vector <pii> adj[MAXN]; int dis[MAXN], di[MAXN]; bool ty[MAXN]; priority_queue<pii, vector<pii>, greater<pii>> pq; map<pii,int> ma; void dji(int sta){ for(int i=1; i<=n; i++) dis[i] = INF; pq.push({0, sta}); dis[sta] = 0; while(!pq.empty()){ int tp = pq.top().se; int dist = pq.top().fi; pq.pop(); if(dis[tp] < dist) continue; for(auto ed : adj[tp]){ int nx = ed.fi; int wei = ed.se; if(dis[nx] > dist+wei){ dis[nx] = dist+wei; pq.push({dis[nx], nx}); } } } } void dji2(int sta){ for(int i=1; i<=n; i++) di[i] = INF; pq.push({0, sta}); di[sta] = 0; while(!pq.empty()){ int tp = pq.top().se; int dist = pq.top().fi; pq.pop(); if(di[tp] < dist) continue; for(auto ed : adj[tp]){ int nx = ed.fi; int wei = ed.se; if(di[nx] > dist+wei){ di[nx] = dist+wei; pq.push({di[nx], nx}); } } } } signed main(){ //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n >> m; cin >> s >> t; cin >> x >> y; for(int i=1; i<=m; i++){ cin >> u[i] >> v[i] >> c[i]; if(u[i] > v[i]) swap(u[i], v[i]); ma[pii(u[i], v[i])] = i; adj[u[i]].pb({v[i], c[i]}); adj[v[i]].pb({u[i], c[i]}); } dji(s); dji2(t); //cout << dis[t] << " dis\n"; for(int i=1; i<=n; i++){ if(dis[i]+di[i] == dis[t]) ty[i] = 1; } dji(y); int ans = INF; for(int i=1; i<=n; i++) if(ty[i]) ans = min(ans, dis[i]); cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...