Submission #956682

# Submission time Handle Problem Language Result Execution time Memory
956682 2024-04-02T10:13:57 Z peterandvoi Robot (JOI21_ho_t4) C++17
0 / 100
163 ms 35032 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef ngu
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = (int) 5e5 + 5;

int n, m;
long long s[N], d[N];
vector<pair<int, long long>> g[N];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef ngu
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
    #endif
    cin >> n >> m;
    map<pair<int, int>, int> id;
    vector<tuple<int, int, int, int>> edges;
    int idx = n;
    auto add = [&](int u, int c, int v) {
        if (!id.count({u, c})) {
            id[{u, c}] = ++idx;
        }
        s[id[{u, c}]] += v;
    };
    for (int i = 1; i <= m; ++i) {
        int u, v, c, p;
        cin >> u >> v >> c >> p;
        edges.emplace_back(u, v, c, p);
        add(u, c, p);
        add(v, c, p);
    }
    for (auto [u, v, c, p] : edges) {
        int x = id[{u, c}], y = id[{v, c}];
        long long a = s[x], b = s[y];
        g[u].emplace_back(v, min(1LL * p, a - p));
        g[v].emplace_back(u, min(1LL * p, b - p));
        g[u].emplace_back(y, 0);
        g[v].emplace_back(x, 0);
        g[x].emplace_back(v, a - p);
        g[y].emplace_back(u, b - p);
    }
    memset(d, 0x3f, sizeof(d));
    using T = pair<long long, int>;
    priority_queue<T, vector<T>, greater<T>> pq;
    d[1] = 0;
    pq.emplace(0, 1);
    while (pq.size()) {
        auto [c, u] = pq.top();
        pq.pop();
        if (c == d[u]) {
            for (auto [v, w] : g[u]) {
                if (d[v] > d[u] + w) {
                    pq.emplace(v, d[v] = d[u] + w);
                }
            }
        }
    }
    const long long INF = (long long) 1e18;
    cout << (d[n] > INF ? -1 : d[n]);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 3 ms 16984 KB Output is correct
3 Correct 4 ms 16996 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 4 ms 16988 KB Output is correct
6 Runtime error 17 ms 34140 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 163 ms 35032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 3 ms 16984 KB Output is correct
3 Correct 4 ms 16996 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 4 ms 16988 KB Output is correct
6 Runtime error 17 ms 34140 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -