제출 #827671

#제출 시각아이디문제언어결과실행 시간메모리
827671NhanBeooCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
313 ms24484 KiB
// Judges with GCC >= 12 only needs Ofast // #pragma GCC optimize("Ofast") // #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize") // MLE optimization // #pragma GCC optimize("conserve-stack") // Old judges // #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2") // New judges. Test with assert(__builtin_cpu_supports("avx2")); // #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native") // Atcoder // #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma") #include <bits/stdc++.h> using namespace std; #define int ll #define MAX LLONG_MAX #define st first #define nd second #define endl '\n' #define SZ(x) ((int)x.size()) #define ALL(x) x.begin(), x.end() typedef long long ll; typedef pair< int, int > ii; typedef pair< int, ii > iii; typedef vector< int > vi; typedef vector< ii > vii; typedef vector< iii > viii; typedef vector< vi > vvi; typedef vector< vii > vvii; typedef vector< viii > vviii; const int N = 1e5 + 5; int n, m; vii adj[N]; int um[N], vm[N]; vi flood(int s){ vi dis(n + 1, LLONG_MAX); dis[s] = 0; priority_queue<ii, vii, greater<ii>> q; q.push({0, s}); while(q.size()){ auto [len, u] = q.top(); q.pop(); if(dis[u] != len) continue; for(auto [v, w]: adj[u]){ if(dis[v] > dis[u] + w){ dis[v] = dis[u] + w; q.push({dis[v], v}); } } } return dis; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; int s, t; cin >> s >> t; int u, v; cin >> u >> v; while(m--){ int x, y, z; cin >> x >> y >> z; adj[x].push_back({y, z}); adj[y].push_back({x, z}); } auto S = flood(s), T = flood(t), U = flood(u), V = flood(v); vii dag; for(int i=1; i<=n; i++){ if(S[i] + T[i] != S[t]) continue; dag.push_back({T[i], i}); } sort(ALL(dag)); int ans = U[v]; for(auto [len, x]: dag){ um[x] = U[x]; vm[x] = V[x]; for(auto [y, z]: adj[x]){ if(T[y] + z == len){ um[x] = min(um[x], um[y]); vm[x] = min(vm[x], vm[y]); } } ans = min(ans, um[x] + V[x]); ans = min(ans, vm[x] + U[x]); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...