Submission #1067352

#TimeUsernameProblemLanguageResultExecution timeMemory
1067352LinhLewLewCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
278 ms262144 KiB
// PhuThuyRuntime <3 // A secret makes a woman woman #include <bits/stdc++.h> using namespace std; #define eb emplace_back #define ef emplace_front #define pb push_back #define pf push_front #define all(v) v.begin(), v.end() #define ins insert #define lb lower_bound #define ub upper_bound #define fo(i, l, r) for(int i = l; i <= r; i++) #define foi(i, l, r) for(int i = l; i >= r; i--) #define elif else if #define el cout << "\n"; #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define pil pair<int, ll> #define fi first #define se second #define in(x) freopen(x, "r", stdin) #define out(x) freopen(x, "w", stdout) #define ll long long #define ull unsigned long long #define pob pop_back #define bs binary_search #define vi vector<int> #define vii vector<pair<int, int>> #define getbit(i, j) (i >> j) & 1 #define offbit(i, j) (1 << j) ^ i #define onbit(i, j) (1 << j) | i const int N = 1e5 + 2; const ll mod = 1e9 + 7; const int inf = INT_MAX; const int base = 31; const long double EPS = 1e-9; const long double pi = acos(-1.0); int n, m, S, T, U, V; vii adj[N]; vector<pair<pii, int>> edges; void inp(){ cin >> n >> m >> S >> T >> U >> V; fo(i, 1, m){ int u, v, c; cin >> u >> v >> c; edges.push_back({{u, v}, c}); adj[u].eb(v, c); adj[v].eb(u, c); } } ll dp[N], dpU[N], dpV[N]; void dij(int start, ll DP[]){ fo(i, 1, n) DP[i] = 1e18; priority_queue<pli, vector<pli>, greater<pli>> q; DP[start] = 0; q.push({0, start}); while(!q.empty()){ ll val = q.top().fi; int u = q.top().se; q.pop(); if(val != DP[u]) continue; for(auto [v, w] : adj[u]){ if(DP[v] > DP[u] + w){ DP[v] = DP[u] + w; q.push({DP[v], v}); } } } } ll tot = 1e18; bool exist[N]; bool predfs(int u){ if(exist[u]) return 1; bool ok = (u == T); for(auto [v, w] : adj[u]){ ok = ok || predfs(v); } exist[u] = ok; } ll dfs(int u, ll dp1[], ll dp2[]){ ll ans = 1e18; if(exist[u]) ans = dp2[u]; for(auto [v, w] : adj[u]){ ans = min(ans, dfs(v, dp1, dp2)); } tot = min(tot, dp1[u] + ans); return ans; } void sol(){ dij(S, dp); // fo(i, 1, n) cout << dp[i] << ' '; // el dij(U, dpU); dij(V, dpV); fo(i, 1, n) adj[i].clear(); for(auto [it, w] : edges){ auto [u, v] = it; if(dp[u] == dp[v] + w){ adj[v].eb(u, w); // cout << v << ' ' << u, el } if(dp[v] == dp[u] + w){ adj[u].eb(v, w); // cout << u << ' ' << v, el } } predfs(S); dfs(S, dpU, dpV); dfs(S, dpV, dpU); cout << tot; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); inp(); sol(); return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'bool predfs(int)':
commuter_pass.cpp:82:15: warning: control reaches end of non-void function [-Wreturn-type]
   82 |      exist[u] = ok;
      |      ~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...