제출 #959540

#제출 시각아이디문제언어결과실행 시간메모리
959540mannshah1211Olympic Bus (JOI20_ho_t4)C++17
0 / 100
15 ms3420 KiB
/** * author: hashman * created: **/ #include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); constexpr int64_t inf = 1e18; using P = pair<int64_t, int>; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<pair<int, int>>> adj(n), radj(n); vector<int> u(m), v(m), c(m), d(m); for (int i = 0; i < m; i++) { cin >> u[i] >> v[i] >> c[i] >> d[i]; u[i]--; v[i]--; adj[u[i]].push_back(make_pair(v[i], c[i])); radj[v[i]].push_back(make_pair(u[i], c[i])); } auto dijkstra = [&](int source) { vector<int64_t> dist(n, inf); dist[source] = 0; priority_queue<P, vector<P>, greater<P>> pq; pq.push(make_pair(0, source)); while (!pq.empty()) { auto [expected, v] = pq.top(); pq.pop(); if (expected != dist[v]) { continue; } for (auto [now, wt] : adj[v]) { if (dist[now] > dist[v] + wt) { dist[now] = dist[v] + wt; pq.push(make_pair(dist[now], now)); } } } return dist; }; vector<int64_t> from_source = dijkstra(0); vector<int64_t> from_dest = dijkstra(n - 1); int64_t mn = inf; mn = min(mn, from_source[n - 1] + from_dest[0]); for (int i = 0; i < m; i++) { int64_t from = from_source[v[i]] + from_dest[u[i]], to = from_dest[v[i]] + from_source[u[i]]; if (from > inf || to > inf) { continue; } mn = min(mn, from + d[i] + to); } cout << ((mn == inf) ? -1 : mn) << '\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...