제출 #465122

#제출 시각아이디문제언어결과실행 시간메모리
465122Marslai24Commuter Pass (JOI18_commuter_pass)C++14
100 / 100
708 ms32272 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() const int INF = 1e18, MOD = 1e9 + 7, N = 1e5 + 1; void setIO(string name = ""){ ios::sync_with_stdio(false); cin.tie(0); if(name.size()){ freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } using pii = pair<int, int>; vector<pii> adj[N]; int disu[N], disv[N], diss[N], vis[N], ans, dp[2][N]; void getdis(int start, int dis[]){ fill(vis, vis + N, false); priority_queue<pii> pq; pq.push({0, start}); dis[start] = 0; while(!pq.empty()){ int c, cur; tie(c, cur) = pq.top(); pq.pop(); if(!vis[cur]){ dis[cur] = -c; vis[cur] = 1; for(auto nxt : adj[cur])pq.push({c - nxt.first, nxt.second}); } } } void dijkstra(int start, int end){ fill(vis, vis + N, false); fill(dp[0], dp[0] + N, INF); fill(dp[1], dp[1] + N, INF); priority_queue<pair<int, pii>> pq; pq.push({0, {start, 0}}); while(!pq.empty()){ int c, cur, par; pii tmp; tie(c, tmp) = pq.top(); tie(cur, par) = tmp; pq.pop(); if(!vis[cur]){ vis[cur] = 1; dp[0][cur] = min(disu[cur], dp[0][par]); dp[1][cur] = min(disv[cur], dp[1][par]); diss[cur] = -c; for(auto nxt : adj[cur])pq.push({c - nxt.first, {nxt.second, cur}}); }else if(diss[cur] == -c){ if(min(disu[cur], dp[0][par]) + min(disv[cur], dp[1][par]) < dp[0][cur] + dp[1][cur]){ dp[0][cur] = min(disu[cur], dp[0][par]); dp[1][cur] = min(disv[cur], dp[1][par]); } } } ans = min(ans, dp[0][end] + dp[1][end]); } signed main(){ setIO(); int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v; for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; adj[a].push_back({c, b}); adj[b].push_back({c, a}); } getdis(u, disu); getdis(v, disv); ans = disu[v]; dijkstra(s, t); dijkstra(t, s); cout << ans; }

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

commuter_pass.cpp: In function 'void setIO(std::string)':
commuter_pass.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen((name + ".out").c_str(), "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...