Submission #825839

#TimeUsernameProblemLanguageResultExecution timeMemory
825839AmirElarbiOlympic Bus (JOI20_ho_t4)C++14
0 / 100
1 ms468 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #define INF 1e9 #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 = 400+5; const int kax = 2+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>; vi adj[nax]; int x[nax], y[nax], c[nax], d[nax]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,m; cin >> n >> m; for (int i = 0; i < m; ++i) { cin >> x[i] >> y[i] >> c[i] >> d[i]; adj[x[i]].pb(i); } int aff = INF; for (int i = 0; i < m; ++i) { priority_queue<ii, vii, greater<ii>> pq; vi dist(n+1, INF); dist[1] = 0; pq.push({0, 1}); while(!pq.empty()){ int cst = pq.top().fi, u = pq.top().se; pq.pop(); if(dist[u] != cst) continue; for(auto j : adj[u]){ if(j == i) continue; if(dist[y[j]] > c[j] + dist[u]){ dist[y[j]] = c[j] + dist[u]; pq.push({dist[y[j]], y[j]}); } } if(u == y[i] && dist[x[i]] > d[i] + c[i] + dist[u]) { dist[x[i]] = d[i] + c[i] + dist[u]; pq.push({dist[x[i]], x[i]}); } } int ans = dist[n]; dist.clear(); dist.assign(n+1,INF); dist[n] = 0; pq.push({0,n}); while(!pq.empty()){ int cst = pq.top().fi, u = pq.top().se; pq.pop(); if(dist[u] != cst) continue; for(auto j : adj[u]){ if(j == i) continue; if(dist[y[j]] > c[j] + dist[u]){ dist[y[j]] = c[j] + dist[u]; pq.push({dist[y[j]], y[j]}); } } if(u == y[i] && dist[x[i]] > d[i] + c[i] + dist[u]) { dist[x[i]] = d[i] + c[i] + dist[u]; pq.push({dist[x[i]], x[i]}); } } ans += dist[1]; aff = min(aff, ans); } 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...