This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |