#include "shortcut.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <set>
#include <map>
#include <queue>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <functional>
using namespace std;
const int N = 1000;
const long long INF = 1e18 + 228;
vector< pair<int, int> > g[N];
void AddEdge(int u, int v, int w) {
g[u].emplace_back( v, w );
g[v].emplace_back( u, w );
}
long long dist[N][N];
void dfs(int v, int st, long long DST = 0, int par = -1) {
dist[v][st] = DST;
for (auto go : g[v]) {
int to = go.first;
int w = go.second;
dfs(to, st, DST + w, v);
}
}
long long find_shortcut(int n, vector<int> l, vector<int> d, int c)
{
for (int i = 0; i < n - 1; ++i) {
AddEdge(i, i + 1, l[i]);
}
for (int i = 0; i < n; ++i) {
AddEdge(i, n + i, d[i]);
}
int V = 2 * n - 1;
for (int i = 0; i < V; ++i) {
dfs(i, i);
}
long long best = INF;
for (int A = 0; A < n; ++A) {
for (int B = A + 1; B < n; ++B) {
long long cur_dia = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
long long cur = min({dist[i][j], dist[i][A] + c + dist[j][B], dist[i][B] + c + dist[j][A]});
cur = cur + d[i] + d[j];
cur_dia = max(cur_dia, cur);
if (cur_dia > best) {
break;
}
}
if (cur_dia > best) {
break;
}
}
if (cur_dia < best) {
best = cur_dia;
}
}
}
return best;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
325 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
325 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
325 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
325 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
325 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
325 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
325 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
325 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |