제출 #1124504

#제출 시각아이디문제언어결과실행 시간메모리
1124504seoul_koreaCommuter Pass (JOI18_commuter_pass)C++17
15 / 100
296 ms21912 KiB
#include <bits/stdc++.h> using namespace std; #define int long long using ii = pair<int, int>; #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)7e18; 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; 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; int fk1, fk2; fk1 = min(dp[par][0], du[u]); fk2 = min(dp[par][1], dv[u]); if(fk1 + fk2 <= dp[u][0] + dp[u][1]) { dp[u][0] = fk1; dp[u][1] = fk2; } 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}); } memset(du, 0x3f, sizeof du); memset(dv, 0x3f, sizeof dv); Precompute(l, du); Precompute(r, dv); ans = du[r]; Calc(s, t); Calc(t, s); cout << ans << '\n'; return 0; } /* 6 6 1 6 6 4 1 2 1 2 3 1 3 5 1 2 4 3 4 5 2 5 6 1 */

컴파일 시 표준 에러 (stderr) 메시지

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