Submission #944161

#TimeUsernameProblemLanguageResultExecution timeMemory
944161dwuyCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
265 ms26864 KiB
#include <bits/stdc++.h> #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL) #define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout) #define fi first #define se second #define endl "\n" #define len(s) int32_t(s.length()) #define MASK(k)(1LL<<(k)) #define TASK "test" #define int long long using namespace std; typedef tuple<int, int, int> tpiii; typedef pair<double, double> pdd; typedef pair<int, int> pii; typedef long long ll; const long long OO = 1e18; const int MOD = 1e9 + 7; const int INF = 1e9; const int MX = 200005; int n, m; int S, T, U, V; vector<pii> G[MX]; void nhap(){ cin >> n >> m; cin >> S >> T >> U >> V; for(int i=1; i<=m; i++){ int u, v, c; cin >> u >> v >> c; G[u].push_back({v, c}); G[v].push_back({u, c}); } } void dijkstra(int u, int *d){ for(int i=1; i<=n; i++) d[i] = 1e18; priority_queue<pii> Q; Q.push({0, u}); d[u] = 0; while(Q.size()){ int du, u; tie(du, u) = Q.top(); du = -du; Q.pop(); if(du != d[u]) continue; for(pii &tmp: G[u]){ int v, c; tie(v, c) = tmp; c += du; if(c < d[v]){ d[v] = c; Q.push({-c, v}); } } } } int dS[MX]; int dT[MX]; int dU[MX]; int dV[MX]; int f1[MX]; int f2[MX]; void solve(){ dijkstra(S, dS); dijkstra(T, dT); dijkstra(U, dU); dijkstra(V, dV); int ans = dU[V]; bitset<MX> vist = 0; vector<int> vt(n); for(int i=1; i<=n; i++) vt[i-1] = i; function<bool(const int &, const int &)> comp = [&](const int &a, const int &b){ return dS[a] < dS[b]; }; sort(vt.begin(), vt.end(), comp); for(int u: vt) if(dS[u] + dT[u] == dS[T]){ f1[u] = dU[u]; f2[u] = dV[u]; for(pii tmp: G[u]){ int v, c; tie(v, c) = tmp; if(dS[v] + c == dS[u]){ f1[u] = min(f1[u], f1[v]); f2[u] = min(f2[u], f2[v]); } } ans = min({ans, f1[u] + dV[u], f2[u] + dU[u]}); } cout << ans; } int32_t main(){ fastIO; //file(TASK); nhap(); solve(); return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'void solve()':
commuter_pass.cpp:75:16: warning: variable 'vist' set but not used [-Wunused-but-set-variable]
   75 |     bitset<MX> vist = 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...