This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "shortcut.h"
VL distances(VVPI& gp, int s) {
int n = gp.size();
priority_queue<PLL> pq;
VL dist(n, 1e18);
VI vis(n);
pq.push({0, s});
dist[s] = 0;
while (pq.size()) {
int u = pq.top().ss;
pq.pop();
if (vis[u]) continue;
vis[u] = true;
for (auto[v, w] : gp[u]) {
if (dist[u] + w < dist[v]) {
dist[v] = dist[u] + w;
pq.push({-dist[v], v});
}
}
}
return dist;
}
ll vmax(VL a) {
ll ret = 0;
for (ll x : a) setmax(ret, x);
return ret;
}
ll diameter(VVPI& gp) {
int n = gp.size();
ll ret = 0;
rep(u, n) setmax(ret, vmax(distances(gp, u)));
return ret;
}
ll find_shortcut(int n, VI l, VI d, int c) {
VVPI gp(2*n);
rep(u, n) {
gp[u].pb({u+n, d[u]});
gp[u+n].pb({u, d[u]});
}
rep(u, n-1) {
gp[u].pb({u+1, l[u]});
gp[u+1].pb({u, l[u]});
}
ll ans = 1e18;
replr(l, 0, n-1) replr(r, l, n-1) {
gp[l].pb({r, c});
gp[r].pb({l, c});
setmin(ans, diameter(gp));
gp[l].pop_back();
gp[r].pop_back();
}
return ans;
}
Compilation message (stderr)
shortcut.cpp: In function 'VL distances(VVPI&, int)':
shortcut.cpp:46:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
46 | for (auto[v, w] : gp[u]) {
| ^
# | 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... |