Submission #1294093

#TimeUsernameProblemLanguageResultExecution timeMemory
1294093tunademayoRobot (JOI21_ho_t4)C++20
0 / 100
71 ms14008 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define pb push_back

const int N = 1e5+5, M = 2e5+5;
vector<array<int, 3>> g[N];
ll di[N], S[M], mn[M];
bool vis[N];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int u, v, w, c;
        cin >> u >> v >> c >> w;
        g[u].pb({v, w, c});
        g[v].pb({u, w, c});
    }
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> pq;
    fill(di, di+n+1, 1e18);
    di[1] = 0;
    pq.push({0, 1});
    while (!pq.empty()) {
        auto [D, s] = pq.top(); pq.pop();
        if (vis[s]) continue;
        vis[s] = 1;
        for (auto [u, w, c] : g[s]) mn[c] = 1e18, S[c] = 0;
        for (auto [u, w, c] : g[s]) S[c] += w;
        for (auto [u, w, c] : g[s]) mn[c] = min(mn[c], di[u] + S[c]);
        for (auto [u, w, c] : g[s]) {
            if (di[u] > min({di[s] + w, di[s] + S[c] - w, (ll)1e18})) {
                di[u] = min({di[s] + w, di[s] + S[c] - w, (ll)1e18});
                pq.push({di[u], u});
            }
        }
    }
    cout << (di[n] > 1e15 ? -1 : di[n]) << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...