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 <bits/stdc++.h>
using namespace std;
#include "shortcut.h"
#define ll long long
#define pii array<ll, 2>
ll dijkstra(vector<vector<pii>> &g, int source) {
int n=(int)g.size();
vector<ll> dis(n, (int)1e16);
dis[source]=0;
priority_queue<pii> pq;
for (int i=0;i<n;i++) {
pq.push({-dis[i], i});
}
vector<bool> vis(n, false);
while (!pq.empty()) {
auto [d, node] = pq.top();pq.pop();
if (vis[node]) continue;
vis[node]=true;
for (auto [ne, we] : g[node]) {
if (dis[node] + we < dis[ne]) {
dis[ne] = dis[node] + we;
pq.push({-dis[ne], ne});
}
}
}
return *max_element(dis.begin(), dis.end());
}
ll diameter(vector<vector<pii>> &g) {
ll dis = 0;
for (int i=0;i<(int)g.size();i++) {
dis = max(dis, dijkstra(g, i));
}
return dis;
}
long long find_shortcut(int n, std::vector <int> l, std::vector <int> d, int c) {
int tmp = n;
for (int i=0;i<n;i++)if (d[i]) tmp++;
vector<vector<pii>> g(tmp);
for (int i=0;i<n-1;i++) {
g[i].push_back({i+1, (ll)l[i]});
g[i+1].push_back({i, (ll)l[i]});
}
int lst = n;
for (int i=0;i<n;i++) {
if (d[i] == 0) continue;
g[i].push_back({lst, (ll)d[i]});
g[lst].push_back({i, (ll)d[i]});
lst++;
}
ll mxDis = diameter(g);
for (int i=0;i<n;i++) {
for (int j=i+1;j<n;j++) {
g[i].push_back({j, (ll)c});
g[j].push_back({i, (ll)c});
mxDis = min(mxDis, diameter(g));
g[i].pop_back();
g[j].pop_back();
}
}
return mxDis;
}
Compilation message (stderr)
shortcut.cpp: In function 'long long int dijkstra(std::vector<std::vector<std::array<long long int, 2> > >&, int)':
shortcut.cpp:19:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
19 | auto [d, node] = pq.top();pq.pop();
| ^
shortcut.cpp:23:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
23 | for (auto [ne, we] : g[node]) {
| ^
# | 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... |