Submission #757565

# Submission time Handle Problem Language Result Execution time Memory
757565 2023-06-13T10:46:13 Z Desh03 Olympic Bus (JOI20_ho_t4) C++17
5 / 100
1000 ms 4504 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1e18;
vector<multiset<pair<int, int>>> g;

void djikstra(int src, vector<long long> &sp) {
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
    pq.push({sp[src] = 0, src});
    while (pq.size()) {
        int u = pq.top().second;
        pq.pop();
        for (auto [v, w] : g[u]) {
            if (sp[u] + w < sp[v])
                sp[v] = sp[u] + w, pq.push({sp[v], v});
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    g.resize(n);
    vector<long long> sp1, sp2;
    vector<tuple<int, int, int, int>> edges;
    for (int i = 0; i < m; i++) {
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        --u, --v;
        g[u].insert({v, c});
        edges.push_back({u, v, c, d});
    }
    sp1 = sp2 = vector<long long> (n, INF);
    djikstra(0, sp1), djikstra(n - 1, sp2);
    long long ans = min(INF, sp1[n - 1] + sp2[0]);
    for (auto [u, v, c, d] : edges) {
        g[u].erase(g[u].find({v, c}));
        g[v].insert({u, c});
        sp1 = sp2 = vector<long long> (n, INF);
        djikstra(0, sp1), djikstra(n - 1, sp2);
        ans = min(ans, sp1[n - 1] + sp2[0] + d);
        g[v].erase(g[v].find({u, c}));
        g[u].insert({v, c});
    }
    cout << (ans == INF ? -1 : ans) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 69 ms 404 KB Output is correct
4 Correct 71 ms 408 KB Output is correct
5 Correct 53 ms 384 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 21 ms 404 KB Output is correct
10 Correct 104 ms 404 KB Output is correct
11 Correct 106 ms 340 KB Output is correct
12 Correct 112 ms 340 KB Output is correct
13 Correct 29 ms 340 KB Output is correct
14 Correct 43 ms 340 KB Output is correct
15 Correct 37 ms 340 KB Output is correct
16 Correct 45 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 4504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Execution timed out 1084 ms 3588 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 69 ms 404 KB Output is correct
4 Correct 71 ms 408 KB Output is correct
5 Correct 53 ms 384 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 21 ms 404 KB Output is correct
10 Correct 104 ms 404 KB Output is correct
11 Correct 106 ms 340 KB Output is correct
12 Correct 112 ms 340 KB Output is correct
13 Correct 29 ms 340 KB Output is correct
14 Correct 43 ms 340 KB Output is correct
15 Correct 37 ms 340 KB Output is correct
16 Correct 45 ms 332 KB Output is correct
17 Execution timed out 1061 ms 4504 KB Time limit exceeded
18 Halted 0 ms 0 KB -