제출 #758907

#제출 시각아이디문제언어결과실행 시간메모리
758907xyzxyzOlympic Bus (JOI20_ho_t4)C++17
37 / 100
1039 ms9000 KiB
#include<bits/stdc++.h> #define int long long using namespace std; vector<int> kosten; void dijkstra(vector<set<pair<int,int>>>& adj, vector<long long>& dist, int start, vector<pair<int,int>>&parent){ priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq; dist[start] = 0; pq.push({0,start}); while(!pq.empty()){ int wo = pq.top().second, preis = pq.top().first; pq.pop(); if(dist[wo]== preis){ for(auto[ziel, index]: adj[wo]){ if(dist[ziel] > kosten[index]+preis){ dist[ziel] = kosten[index]+preis; parent[ziel] = {wo, index}; pq.push({dist[ziel], ziel}); } } } } } signed main(){ ios::sync_with_stdio(false); cin.tie(0); int v, e; cin >> v >> e; vector<set<pair<int,int>>> adj(v), adj2(v); vector<tuple<int,int,int,int>> edges(e); vector<int> umdrehkosten(e); kosten = vector<int>(e); for(int i=0; i<e; i++){ int a, b; cin >> a >> b >> kosten[i] >> umdrehkosten[i]; a--; b--; adj[a].insert({b, i}); adj2[b].insert({a, i});//umgedrehter Graph edges[i] = make_tuple(a,b,kosten[i],umdrehkosten[i]); } vector<long long> von0(v, 1e17), vonn_r(v, 1e17), vonn(v, 1e17), von0_r(v, 1e17); vector<pair<int,int>> parent0(v, {-1, -1}), parent2(v, {-1, -1}), parentn(v, {-1, -1}); dijkstra(adj, von0, 0, parent0); dijkstra(adj2, vonn_r, v-1, parent2); dijkstra(adj2, von0_r, 0, parent2); dijkstra(adj, vonn, v-1, parentn); int ort = v-1; vector<bool> used(e, false); while(parent0[ort].first!=-1){ used[parent0[ort].second] = true; ort = parent0[ort].first; } ort = 0; while(parentn[ort].first!=-1){ used[parentn[ort].second] = true; ort = parentn[ort].first; } int res = min((long long)1e17, (long long)von0[v-1]+vonn[0]);//keine Kante gedreht for(int i=0; i<e; i++){ auto [start, ende, cost, r_cost] = edges[i]; if(used[i]){ adj[start].erase({ende, i}); adj[ende].insert({start, i}); vector<long long> dist(v, 1e17), dist2(v, 1e17); dijkstra(adj, dist, 0, parent0); dijkstra(adj, dist2, v-1, parent0); res = min(res, dist[v-1]+dist2[0]+r_cost); adj[start].insert({ende, i}); adj[ende].erase({start, i}); }else{ int a = min(vonn[0], vonn[ende] + cost + von0_r[start]); int b = min(von0[v-1], von0[ende] + cost + vonn_r[start]); res = min(res, a + b + r_cost); } } if(res!=1e17) cout << res; else cout << -1; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...