Submission #492908

#TimeUsernameProblemLanguageResultExecution timeMemory
492908dxz05Shortcut (IOI16_shortcut)C++14
0 / 100
16 ms23784 KiB
#include "shortcut.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

vector<pair<int, int>> g[1000010];
ll diam(int n, int c, vector<int> &d, int x, int y){
    g[x].emplace_back(y, c);
    g[y].emplace_back(x, c);

    ll res = 0;
    for (int i = 0; i < n; i++){
        priority_queue<pair<ll, int>> q;
        q.push({0, i});

        vector<bool> processed(n, false);
        vector<ll> dist(n, 1e9);
        dist[i] = 0;

        while (!q.empty()){
            int v = q.top().second; q.pop();
            if (processed[v]) continue;
            processed[v] = true;

            for (auto edge : g[v]){
                int u = edge.first, w = edge.second;
                if (dist[u] > dist[v] + w){
                    dist[u] = dist[v] + w;
                    q.push({-dist[u], u});
                }
            }
        }

        for (int j = 0; j < n; j++){
            if (j != i) res = max(res, d[i] + dist[j] + d[j]);
        }
    }

    g[x].pop_back();
    g[y].pop_back();

    return res;
}

long long find_shortcut(int n, vector<int> l, vector<int> d, int c){
    for (int i = 0; i < n - 1; i++){
        g[i].emplace_back(i + 1, l[i]);
        g[i + 1].emplace_back(i, l[i]);
    }

    ll res = 1e18;
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            res = min(res, diam(n, c, d, i, j));
        }
    }

    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...