Submission #1167619

#TimeUsernameProblemLanguageResultExecution timeMemory
1167619dianaCommuter Pass (JOI18_commuter_pass)C++20
0 / 100
450 ms13288 KiB
#include <bits/stdc++.h> #pragma GCC oprimize("O3, unroll-loops") #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") #define c first #define v second using namespace std; typedef long long ll; typedef pair<int, int> edge; const ll N = 1e5+5, M = 1e18; vector<edge> graf[N]; int n, m, s, t, u, v; ll dfv[N], dfs[N], dft[N]; void start() { for(int i=0; i<N; i++) dfv[i] = M, dfs[i] = M, dft[i] = M; } void dijfromU() { priority_queue<edge, vector<edge>, greater<edge>> pq; pq.push({0, v}); dfv[v] = 0; while(!pq.empty()) { edge t = pq.top(); pq.pop(); for(auto x: graf[t.v]) { if(t.c + x.c < dfv[x.v]) { pq.push({t.c + x.c, x.v}); dfv[x.v] = t.c + x.c; } } } } void dijfromS() { priority_queue<edge, vector<edge>, greater<edge>> pq; pq.push({0, s}); dfs[s] = 0; while(!pq.empty()) { edge t = pq.top(); pq.pop(); for(auto x: graf[t.v]) { if(t.c + x.c < dfs[x.v]) { pq.push({t.c + x.c, x.v}); dfs[x.v] = t.c + x.c; } } } } void dijfromT() { priority_queue<edge, vector<edge>, greater<edge>> pq; pq.push({0, t}); dft[t] = 0; while(!pq.empty()) { edge t = pq.top(); pq.pop(); for(auto x: graf[t.v]) { if(t.c + x.c < dft[x.v]) { pq.push({t.c + x.c, x.v}); dft[x.v] = t.c + x.c; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); start(); int n, m; cin >> n >> m >> s >> t >> u >> v; while(m--) { int a, b, c; cin >> a >> b >> c; graf[a].push_back({c, b}); graf[b].push_back({c, a}); } dijfromT(); dijfromU(); dijfromS(); ll ans = M, d=M; for(int i=1; i<=n; i++) { if(dft[i]+dfs[i]==d) ans = min(ans, dfv[i]); else if(dft[i]+dfs[i]<d) ans = dfv[i], d = dft[i]+dfs[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...