제출 #485811

#제출 시각아이디문제언어결과실행 시간메모리
485811Jarif_RahmanOlympic Bus (JOI20_ho_t4)C++17
5 / 100
1088 ms3172 KiB
#include <iostream> #include <vector> #include <array> #include <queue> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll inf = 1e17; int edges[50000][4]; vector<pair<int, ll>> v[200]; ll dis[50000]; bool bl[50000]; void vclear(){ for(int i = 0; i < 200; i++) v[i].clear(); } void clear(){ for(int i = 0; i < 50000; i++) dis[i] = inf, bl[i] = 0; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for(int i = 0; i < m; i++){ cin >> edges[i][0] >> edges[i][1] >> edges[i][2] >> edges[i][3]; edges[i][0]--, edges[i][1]--; } ll ans = inf; for(int tt = 0; tt <= m; tt++){ vclear(); ll cur = 0; for(int i = 0; i < m; i++){ if(tt == i){ v[edges[i][1]].pb({edges[i][0], edges[i][2]}); cur+=edges[i][3]; } else{ v[edges[i][0]].pb({edges[i][1], edges[i][2]}); } } priority_queue<pair<ll, int>> pq; clear(); dis[0] = 0; pq.push({0, 0}); while(!pq.empty()){ int nd = pq.top().sc; pq.pop(); if(bl[nd]) continue; bl[nd] = 1; for(auto [x, w]: v[nd]) if(dis[nd]+w < dis[x]){ dis[x] = dis[nd]+w; pq.push({-dis[x], x}); } } cur+=dis[n-1]; cur = min(cur, inf); clear(); dis[n-1] = 0; pq.push({0, n-1}); while(!pq.empty()){ int nd = pq.top().sc; pq.pop(); if(bl[nd]) continue; bl[nd] = 1; for(auto [x, w]: v[nd]) if(dis[nd]+w < dis[x]){ dis[x] = dis[nd]+w; pq.push({-dis[x], x}); } } cur+=dis[0]; ans = min(ans, cur); } if(ans >= inf) ans = -1; cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...