Submission #535753

#TimeUsernameProblemLanguageResultExecution timeMemory
535753abc864197532Olympic Bus (JOI20_ho_t4)C++17
0 / 100
416 ms2444 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define eb emplace_back #define pb push_back #define pii pair<int,int> #define X first #define Y second #define all(x) x.begin(), x.end() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T i, U ...j) { cout << i << ' ', abc(j...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } #ifdef Doludu #define test(x...) abc("[" + string(#x) + "]", x) #define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #else #define test(x...) void(0) #define owo ios::sync_with_stdio(false), cin.tie(0) #endif const int N = 205, M = 500001; array <int, 4> E[M]; lli dis[N][N][N]; // dis[i][j][k] -> from i to k, forbid j vector <int> adj[N]; lli dis2[N][N]; void build(int s, int forbid, int n) { for (int i = 0; i < n; ++i) { dis[s][forbid][i] = 1 << 30; } dis[s][forbid][s] = 0; if (s == forbid) return; priority_queue <pii, vector <pii>, greater <pii>> pq; pq.emplace(0, s); while (!pq.empty()) { int d, v; tie(d, v) = pq.top(); pq.pop(); if (d < dis[s][forbid][v]) continue; for (int id : adj[v]) { int u = E[id][0] ^ E[id][1] ^ v; if (u == forbid) continue; if (dis[s][forbid][u] > d + E[id][2]) dis[s][forbid][u] = d + E[id][2], pq.emplace(dis[s][forbid][u], u); } } } int main () { owo; int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) dis2[i][j] = 1 << 30; for (int i = 0; i < n; ++i) dis2[i][i] = 0; for (int i = 0, u, v, c, d; i < m; ++i) { cin >> u >> v >> c >> d, --u, --v; E[i] = {u, v, c, d}; adj[u].pb(i); dis2[u][v] = min(dis2[u][v], 1ll * c); } for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) dis2[i][j] = min(dis2[i][j], dis2[i][k] + dis2[k][j]); for (int i = 0; i < n; ++i) { build(0, i, n); build(n - 1, i, n); } lli ans = dis2[0][n - 1] * 2; for (int i = 0; i < m; ++i) { int u = E[i][0], v = E[i][1]; ans = min(ans, E[i][3] + min(dis[0][u][v] + E[i][2] + dis[n - 1][v][u], dis2[0][n - 1]) + min(dis[n - 1][u][v] + E[i][2] + dis[0][v][u], dis2[n - 1][0])); } cout << (ans >= (1ll << 30) ? -1 : ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...