Submission #1124482

#TimeUsernameProblemLanguageResultExecution timeMemory
1124482seoul_koreaCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
238 ms17820 KiB
#include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; #define int long long #define F first #define S second #define REP(i, n) for(int i = 1; i <= n; i++) #define FOR(i, a, b) for(auto i = a; i <= b; i++) #define FORD(i, a, b) for(auto i = a; i >= b; i--) template<class T> bool maximize(T& a, T b) { if(a < b) return a = b, 1; return 0; } template<class T> bool minimize(T& a, T b) { if(a > b) return a = b, 1; return 0; } mt19937 rng(time(0)); const int N = (int)1e5 + 7, INF = (int)8e18; vector<ii> adj[N]; int dp[N][2]; int du[N], dv[N], d[N]; int n, m, s, t, l, r; void Precompute(int start, int dist[]) { priority_queue<ii> pq; fill(dist, dist + n + 1, INF); dist[start] = 0; pq.push({0, start}); while(pq.size()) { int u, f; tie(f, u) = pq.top(); pq.pop(); f = -f; if(dist[u] != f) continue; for(ii nxt : adj[u]) { int v, w; tie(v, w) = nxt; if(minimize(dist[v], f + w)) pq.push({-dist[v], v}); } } } int ans; void Calc(int st, int en) { priority_queue<array<int, 3>> pq; memset(dp, 0x3f, sizeof dp); fill(d, d + n + 1, INF); d[st] = 0; pq.push({0, st, 0}); while(pq.size()) { int f, u, par; array<int, 3> TOP = pq.top(); f = TOP[0]; u = TOP[1]; par = TOP[2]; pq.pop(); f = -f; if(d[u] != f) continue; dp[u][0] = min(dp[par][0], du[u]); dp[u][1] = min(dp[par][1], dv[u]); for(ii nxt : adj[u]) { int v, w; tie(v, w) = nxt; if(minimize(d[v], f + w)) pq.push({-d[v], v, u}); } } minimize(ans, dp[en][0] + dp[en][1]); } signed main(void) { cin.tie(nullptr)->sync_with_stdio(false); #define TASK "CPASS" if(fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } cin >> n >> m; cin >> s >> t; cin >> l >> r; REP(i, m) { int u, v, w; cin >> u >> v >> w; adj[u].push_back({v, w}); adj[v].push_back({u, w}); } Precompute(l, du); Precompute(r, dv); ans = du[r]; Calc(s, t); Calc(t, s); cout << ans << '\n'; return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen(TASK".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...