제출 #1181548

#제출 시각아이디문제언어결과실행 시간메모리
1181548nekolieRobot (JOI21_ho_t4)C++20
100 / 100
81 ms15344 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n,m; cin >> n >> m;
    vector<tuple<int,int,int>> g[n+1];
    for (int i = 0; i < m; i++) {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        g[a].push_back({b,c,d}), g[b].push_back({a,c,d});
    }
    bool odw[n+1]; fill(odw,odw+n+1,false);
    long long odl[n+1], suma[m+1], opt[m+1], inf = 1000000000000000007; fill(odl,odl+n+1,inf);
    priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> q;
    odl[1] = 0, q.push({0,1});
    while (!q.empty()) {
        long long d = q.top().first;
        int v = q.top().second; q.pop();
        if (odw[v])
            continue;
        odw[v] = true;
        for (auto [u,x,y] : g[v])
            suma[x] = 0, opt[x] = inf;
        for (auto [u,x,y] : g[v])
            suma[x] += y;
        for (auto [u,x,y] : g[v])
            opt[x] = min(opt[x],suma[x]+odl[u]);
        for (auto [u,x,y] : g[v]) {
            long long w = min({odl[v]+y,odl[v]+suma[x]-y,opt[x]-y});
            if (w < odl[u])
                odl[u] = w, q.push({w,u});
        }
    }
    cout << ((odl[n] == inf) ? -1 : odl[n]) << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...