Submission #826022

#TimeUsernameProblemLanguageResultExecution timeMemory
826022AmirElarbiOlympic Bus (JOI20_ho_t4)C++14
11 / 100
18 ms3916 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #define INF 1e15 #define ve vector #define vi ve<int> #define ii pair<int,int> #define vii ve<ii> #define pb push_back #define fi first #define se second #define ll long long using namespace __gnu_pbds; using namespace std; const int nax = 1e4+5; const int kax = 1e5+5; const int MOD = 1e9+7; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; int x[kax], y[kax]; ll c[kax], d[kax]; int n,m; vi adj[2][nax]; ve<ll> dijkstra(int st, bool type){ priority_queue<pair<ll,int>, ve<pair<ll,int>>, greater<pair<ll,int>>> pq; ve<ll> dist(n+1, INF); dist[st] = 0; pq.push({0ll, st}); while(!pq.empty()){ ll cst = pq.top().fi; int u = pq.top().se; pq.pop(); if(dist[u] != cst) continue; for(auto j : adj[type][u]){ int to = y[j]; if(type) to = x[j]; if(dist[to] > (c[j] + dist[u])){ dist[to] = c[j] + dist[u]; pq.push({dist[to], to}); } } } return dist; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < m; ++i) { cin >> x[i] >> y[i] >> c[i] >> d[i]; adj[0][x[i]].pb(i); adj[1][y[i]].pb(i); } ve<ll> dist1 = dijkstra(1, 0); ve<ll> distn = dijkstra(n, 0); ve<ll> distrev1 = dijkstra(1, 1); ve<ll> distrevn = dijkstra(n, 1); ll aff = min(dist1[n] + distn[1], (ll)INF); for (int i = 0; i < m; ++i) { aff = min(aff, dist1[y[i]] + distrevn[x[i]] + distn[1] + c[i] + d[i]); aff = min(aff, dist1[n] + distn[y[i]] + distrev1[x[i]] + c[i] + d[i]); aff = min(aff, dist1[y[i]] + distrevn[x[i]] + distn[y[i]] + distrev1[x[i]] + 2*c[i] + d[i]); } if(aff == INF) cout << -1 << endl; else cout << aff << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...