#include <bits/stdc++.h>
using namespace std;
const long long inf = 9223372036854775807;
vector<vector<long long>> m;
void floyd_warshall(int n){
for(int k=0;k<2*n;k++){
for(int i=0;i<2*n;i++){
for(int j=0;j<2*n;j++){
if((m[i][j]>m[i][k]+m[k][j]) and m[k][j]!=inf and m[i][k] != inf){
m[i][j] = m[i][k] + m[k][j];
}
}
}
}
return;
}
long long diam(vector<vector<long long>> &g, int n){
long long res = 0;
for(int i=0;i<2*n;i++){
for(int j=i;j<2*n;j++){
res = max(res,g[i][j]);
}
}
return res;
}
long long find_shortcut(int n, vector<int> l, vector<int> d, int c){
m = vector<vector<long long>> (2*n,vector<long long>(2*n,inf));
for(int i=0;i<2*n;i++) m[i][i] = 0;
long long ans = inf;
for(int i=0;i<n-1;i++){
m[i][i+1] = (long long) l[i];
m[i+1][i] = (long long) l[i];
}
for(int i=0;i<n;i++){
m[i][n+i] = (long long) d[i];
m[n+i][i] = (long long) d[i];
}
vector<vector<long long>> mm = m;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
// express railroad entre i & j
m[i][j] = c;
m[j][i] = c;
floyd_warshall(n);
ans = min(ans, diam(m,n));
m = mm;
}
}
return ans;
}
/*
int main(){
cout << find_shortcut(3, {1, 1}, {1, 1, 1}, 3) << endl;
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
432 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 |
348 KB |
n = 2, 62 is a correct answer |
6 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3 vs contestant 4 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
432 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 |
348 KB |
n = 2, 62 is a correct answer |
6 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3 vs contestant 4 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
432 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 |
348 KB |
n = 2, 62 is a correct answer |
6 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3 vs contestant 4 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
432 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 |
348 KB |
n = 2, 62 is a correct answer |
6 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3 vs contestant 4 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
432 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 |
348 KB |
n = 2, 62 is a correct answer |
6 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3 vs contestant 4 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
432 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 |
348 KB |
n = 2, 62 is a correct answer |
6 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3 vs contestant 4 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
432 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 |
348 KB |
n = 2, 62 is a correct answer |
6 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3 vs contestant 4 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
432 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 |
348 KB |
n = 2, 62 is a correct answer |
6 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 3 vs contestant 4 |
7 |
Halted |
0 ms |
0 KB |
- |