Submission #769452

#TimeUsernameProblemLanguageResultExecution timeMemory
769452AloraCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
267 ms32304 KiB
#include <bits/stdc++.h> #define name "cownav" #define fi(i,a,b) for(int i = a; i <= b; i++) #define fid(i,a,b) for(int i = a; i >= b; i--) #define ll long long #define int long long #define f first #define se second #define pii pair<ll, int> #define getbit(i, j) ((i >> j) & 1) #define pb push_back #define all(v) v.begin(), v.end() #define maxn 200005 const int M = 1e9 + 7; using namespace std; int n, m, S, T, U, V; vector <pii> g[maxn]; vector <vector<ll>> dp(5, vector<ll>(maxn, 1e18)); void dij(int x, vector <ll> &L){ L[x] = 0; priority_queue <pii> q; q.push({0, x}); while(q.size()){ ll h = -q.top().f; int u = q.top().se; q.pop(); if(h != L[u]) continue; for(auto e: g[u]){ int v = e.f, w = e.se; if(L[v] > L[u] + w){ L[v] = L[u] + w; q.push({-L[v], v}); } } } } ll L[maxn], ans = 1e18; ll sol(int u, ll d, int x){ if(d + dp[1][u] != dp[0][T]) return 1e18; if(L[u] != -1) return L[u]; ll tmp = dp[5 - x][u]; for(auto e: g[u]){ int v = e.f, w = e.se; tmp = min(tmp, sol(v, dp[0][u] + w, x)); } ans = min(ans, dp[x][u] + tmp); return L[u] = tmp; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); //freopen(name".in", "r", stdin); // freopen(name".out", "w", stdout); cin >> n >> m; cin >> S >> T >> U >> V; fi(i, 1, m){ int u, v, z; cin >> u >> v >> z; g[u].pb({v, z}); g[v].pb({u, z}); } dij(S, dp[0]); dij(T, dp[1]); dij(U, dp[2]); dij(V, dp[3]); ans = dp[2][V]; fi(i, 1, n) L[i] = -1; sol(S, 0, 2); fi(i, 1, n) L[i] = -1; sol(S, 0, 3); cout << ans; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:3:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    3 | #define fi(i,a,b) for(int i = a; i <= b; i++)
      |                   ^~~
commuter_pass.cpp:67:5: note: in expansion of macro 'fi'
   67 |     fi(i, 1, n) L[i] = -1; sol(S, 0, 2);
      |     ^~
commuter_pass.cpp:67:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   67 |     fi(i, 1, n) L[i] = -1; sol(S, 0, 2);
      |                            ^~~
commuter_pass.cpp:3:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    3 | #define fi(i,a,b) for(int i = a; i <= b; i++)
      |                   ^~~
commuter_pass.cpp:68:5: note: in expansion of macro 'fi'
   68 |     fi(i, 1, n) L[i] = -1; sol(S, 0, 3);
      |     ^~
commuter_pass.cpp:68:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   68 |     fi(i, 1, n) L[i] = -1; sol(S, 0, 3);
      |                            ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...