Submission #833686

#TimeUsernameProblemLanguageResultExecution timeMemory
833686manhlinh1501Commuter Pass (JOI18_commuter_pass)C++17
16 / 100
288 ms17712 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; using i64 = long long; const i64 oo = 1e18; #define eb emplace_back using pii = pair<int, int>; using pli = pair<i64, int>; int n, m; vector<pii> adj[N]; vector<i64> dist[4]; vector<i64> dp[2]; priority_queue<pli, vector<pli>, greater<pli>> Q; int a[4]; i64 ans = oo; #define S 0 #define T 1 #define U 2 #define V 3 void dijkstra(int u, vector<i64> &dist) { dist.assign(n + 1, oo); Q.emplace(0, u); dist[u] = 0; while(!Q.empty()) { pli top = Q.top(); Q.pop(); int u = top.second; if(dist[u] != top.first) continue; for(auto [v, w] : adj[u]) { if(dist[v] > dist[u] + w) { dist[v] = dist[u] + w; Q.emplace(dist[v], v); } } } } void solve(int type) { vector<pli> res; for(int i = 1; i <= n; i++) { if(dist[S][a[T]] == dist[S][i] + dist[T][i]) res.eb(dist[type][i], i); } sort(res.begin(), res.end()); for(pli x : res) { int u = x.second; dp[0][u] = dist[U][u]; dp[1][u] = dist[V][u]; for(auto [v, w] : adj[u]) { if(dist[type][v] + w == dist[type][u]) { dp[0][u] = min(dp[0][u], dp[0][v]); dp[1][u] = min(dp[1][u], dp[1][v]); } } ans = min(ans, min(dp[0][u] + dist[V][u], dp[1][u] + dist[U][u])); } } int main() { if(fopen(".inp", "r")) { freopen(".inp", "r", stdin); freopen(".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 0; i < 4; i++) cin >> a[i]; for(int i = 1; i <= m; i++) { int u, v, w; cin >> u >> v >> w; adj[u].eb(v, w); adj[v].eb(u, w); } for(int i = 0; i < 4; i++) dijkstra(a[i], dist[i]); // for(int j = 0; j < 4; j++) { // cout << j << " : "; // // for(int i = 1; i <= n; i++) // cout << dist[j][i] << " "; // // cout << "\n"; // } dp[0].assign(n + 1, oo); dp[1].assign(n + 1, oo); solve(0); solve(1); cout << ans; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...