#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
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 |
1 |
Correct |
0 ms |
356 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
440 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3000000000 vs contestant 2147483647 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
440 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3000000000 vs contestant 2147483647 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
440 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3000000000 vs contestant 2147483647 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
440 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3000000000 vs contestant 2147483647 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
440 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3000000000 vs contestant 2147483647 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
440 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3000000000 vs contestant 2147483647 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
440 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3000000000 vs contestant 2147483647 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
344 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
440 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
348 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
348 KB |
n = 2, 2000000001 is a correct answer |
11 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3000000000 vs contestant 2147483647 |
12 |
Halted |
0 ms |
0 KB |
- |