Submission #897678

#TimeUsernameProblemLanguageResultExecution timeMemory
897678avighnaOlympic Bus (JOI20_ho_t4)C++17
5 / 100
1096 ms4476 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll N = 201, M = 50001; ll n, m; vector<pair<ll, ll>> adj[N]; ll c[M], d[M]; pair<ll, ll> edges[M]; vector<ll> sssp(ll source, ll i, bool b) { vector<ll> dist(n + 1, 1e15); dist[source] = 0; priority_queue<pair<ll, ll>> pq; pq.push({0, source}); while (!pq.empty()) { ll node = pq.top().second, _dist = -pq.top().first; pq.pop(); for (auto &nb : adj[node]) { if (edges[nb.second].first != node) { if (!(nb.second == i && b)) { continue; } } else if (nb.second == i and b) { continue; } if (dist[nb.first] > _dist + c[nb.second]) { dist[nb.first] = _dist + c[nb.second]; pq.push({-dist[nb.first], nb.first}); } } } return dist; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (ll i = 1; i <= n; ++i) { adj[i].clear(); } for (ll i = 0, u, v; i < m; ++i) { cin >> u >> v >> c[i] >> d[i]; adj[u].emplace_back(v, i), adj[v].emplace_back(u, i); edges[i] = {u, v}; } ll ans = min((ll)1e15, sssp(1, 0, 0)[n] + sssp(n, 0, 0)[1]); for (ll i = 0; i < m; ++i) { ans = min(ans, d[i] + sssp(1, i, 1)[n] + sssp(n, i, 1)[1]); } if (ans == (ll)1e15) { 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...