Submission #1257052

#TimeUsernameProblemLanguageResultExecution timeMemory
1257052chikien2009Olympic Bus (JOI20_ho_t4)C++20
5 / 100
1095 ms1960 KiB
#include <bits/stdc++.h>

using namespace std;

void setup()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int n, m, a[50001], b[50001], c[50001], d[50001];
long long dist[200];
vector<pair<int, int>> g[200];
long long res;
priority_queue<pair<long long, int>> pq;

inline long long Check(int block)
{
    int node;
    long long ret = 0, cur;
    fill_n(dist, n, 1e18);
    dist[0] = 0;
    pq.push({0, 0});
    while (!pq.empty())
    {
        node = pq.top().second;
        cur = -pq.top().first;
        pq.pop();
        if (cur != dist[node])
        {
            continue;
        }
        for (auto & i : g[node])
        {
            if (i.second != block && dist[i.first] > dist[node] + c[i.second])
            {
                dist[i.first] = dist[node] + c[i.second];
                pq.push({-dist[i.first], i.first});
            }
        }
    }
    ret += dist[n - 1];
    fill_n(dist, n, 1e18);
    dist[n - 1] = 0;
    pq.push({0, n - 1});
    while (!pq.empty())
    {
        node = pq.top().second;
        cur = -pq.top().first;
        pq.pop();
        if (cur != dist[node])
        {
            continue;
        }
        for (auto & i : g[node])
        {
            if (i.second != block && dist[i.first] > dist[node] + c[i.second])
            {
                dist[i.first] = dist[node] + c[i.second];
                pq.push({-dist[i.first], i.first});
            }
        }
    }
    ret += dist[0];
    return ret;
}

int main()
{
    setup();

    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
        g[a[i]].push_back({b[i], i});
    }
    res = min((long long)1e18, Check(-1));
    for (int i = 0; i < m; ++i)
    {
        c[m] = c[i];
        g[b[i]].push_back({a[i], m});
        res = min(res, Check(i) + d[i]);
        g[b[i]].pop_back();
    }
    cout << (res == 1e18 ? -1 : res);
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...