Submission #1087583

#TimeUsernameProblemLanguageResultExecution timeMemory
1087583pqthangvCommuter Pass (JOI18_commuter_pass)C++11
15 / 100
2072 ms177540 KiB
#include<bits/stdc++.h> #define endl "\n" using namespace std; typedef long long ll; const int N = 2e5 + 15; const ll INF = 1e18; int n, m; int U, V, S, T; vector<pair<int, ll>> g[N]; // U: 1, V: 2, S: 3, T: 4 vector<ll> dist[5]; vector<int> adj[N]; ll ans = 0; bool visted[N]; void dijk(vector<ll>& dist, int root){ dist[root] = 0; priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq; pq.push({0,root}); while(!pq.empty()){ ll wu; int u; tie(wu,u) = pq.top(); pq.pop(); if(wu > dist[u]) continue; for(auto [v, wv] : g[u]){ if(dist[v] > dist[u] + wv){ dist[v] = dist[u] + wv; pq.push({dist[v], v}); } } } } void build(int u){ for(auto [v, wv] : g[u]){ if(dist[1][u] + wv + dist[2][v] == dist[1][V]){ adj[u].push_back(v); build(v); } } } // best[i][1] = max dist[i] -> s | best[i][2] = max dist[i] -> t ll best[N][3]; void dfs(int u){ visted[u] = true; best[u][1] = dist[3][u]; best[u][2] = dist[4][u]; for(int v : adj[u]){ if(!visted[v]) dfs(v); best[u][1] = min(best[u][1], best[v][1]); best[u][2] = min(best[u][2], best[v][2]); } ans = min(ans, dist[3][u] + best[u][2]); ans = min(ans, dist[4][u] + best[u][1]); } void solve(){ cin >> n >> m >> U >> V >> S >> T; for(int i = 1; i <= m; i++){ int u, v, w; cin >> u >> v >> w; g[u].push_back({v,w}); g[v].push_back({u,w}); } for(int i = 1; i <= 4; i++) dist[i].resize(n+1, INF); dijk(dist[1], U); dijk(dist[2], V); dijk(dist[3], S); dijk(dist[4], T); build(U); ans = dist[3][T]; dfs(U); cout << ans; } signed main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "bus" if(fopen(task".INP", "r")){ freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } int t; t = 1; //cin >> t; while(t--) solve(); }

Compilation message (stderr)

commuter_pass.cpp: In function 'void dijk(std::vector<long long int>&, int)':
commuter_pass.cpp:28:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   28 |         for(auto [v, wv] : g[u]){
      |                  ^
commuter_pass.cpp: In function 'void build(int)':
commuter_pass.cpp:38:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |     for(auto [v, wv] : g[u]){
      |              ^
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         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...