#include "shortcut.h"
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long int lld;
typedef pair<int,long long int> pii;
vector<pii>nei[1000000];
lld max(lld x, lld y){
if(x<y)return y;
return x;
}
lld min(lld x, lld y){
if(x>y)return y;
return x;
}
int diameter(vector<pii>graph[],int n){
lld ans=0;
for(int i=0;i<n;i++){
queue<pii>q;
lld dist[n];
for(int j=0;j<n;j++)dist[j]=-1;
dist[i]=0;
q.push(pii(i,0));
int it=0;
while(!q.empty()){//it++;
int node=q.front().first;
lld d=q.front().second;
//cout<<node<<" "<<d<<endl;
q.pop();
if(d>dist[node] && dist[node]!=-1)continue;
for(int j=0;j<graph[node].size();j++){
int v=graph[node][j].first;
if(dist[v]==-1 || dist[v]>graph[node][j].second+d){
dist[v]=graph[node][j].second+d;
q.push(pii(v,dist[v]));
}
}
}
for(int j=0;j<n;j++){
//cout<<dist[j]<<" ";
ans=max(ans,dist[j]);
}//cout<<endl;
}return ans;
}
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
for(int i=0;i<n;i++){
nei[i+n].push_back(pii(i,d[i]));
nei[i].push_back(pii(i+n,d[i]));
}
for(int i=0;i<n-1;i++){
nei[i].push_back(pii(i+1,l[i]));
nei[i+1].push_back(pii(i,l[i]));
}
lld ans=1000000000000000000;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
vector<pii> graph[2*n];
for(int k=0;k<2*n;k++){
for(int u=0;u<nei[k].size();u++){
graph[k].push_back(nei[k][u]);
}
}
graph[i].push_back(pii(j,c));
graph[j].push_back(pii(i,c));
ans=min(ans,diameter(graph,2*n));
//cout<<diameter(graph,2*n)<<" "<<i<<" "<<j<<endl;
}
}
ans=min(ans,diameter(nei,2*n));
//cout<<diameter(nei,2*n)<<endl;
return ans;
}
Compilation message
shortcut.cpp: In function 'int diameter(std::vector<std::pair<int, long long int> >*, int)':
shortcut.cpp:35:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<graph[node].size();j++){
~^~~~~~~~~~~~~~~~~~~
shortcut.cpp:28:7: warning: unused variable 'it' [-Wunused-variable]
int it=0;
^~
shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:64:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int u=0;u<nei[k].size();u++){
~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
23800 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
30 ms |
23800 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
27 ms |
23984 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
24 ms |
23984 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
24 ms |
23984 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
29 ms |
23988 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
24064 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
25 ms |
24064 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
27 ms |
24064 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
24064 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
23800 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
30 ms |
23800 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
27 ms |
23984 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
24 ms |
23984 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
24 ms |
23984 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
29 ms |
23988 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
24064 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
25 ms |
24064 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
27 ms |
24064 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
24064 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
23800 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
30 ms |
23800 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
27 ms |
23984 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
24 ms |
23984 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
24 ms |
23984 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
29 ms |
23988 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
24064 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
25 ms |
24064 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
27 ms |
24064 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
24064 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
23800 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
30 ms |
23800 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
27 ms |
23984 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
24 ms |
23984 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
24 ms |
23984 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
29 ms |
23988 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
24064 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
25 ms |
24064 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
27 ms |
24064 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
24064 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
23800 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
30 ms |
23800 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
27 ms |
23984 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
24 ms |
23984 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
24 ms |
23984 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
29 ms |
23988 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
24064 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
25 ms |
24064 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
27 ms |
24064 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
24064 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
23800 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
30 ms |
23800 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
27 ms |
23984 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
24 ms |
23984 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
24 ms |
23984 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
29 ms |
23988 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
24064 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
25 ms |
24064 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
27 ms |
24064 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
24064 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
23800 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
30 ms |
23800 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
27 ms |
23984 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
24 ms |
23984 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
24 ms |
23984 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
29 ms |
23988 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
24064 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
25 ms |
24064 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
27 ms |
24064 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
24064 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
23800 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
30 ms |
23800 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
27 ms |
23984 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
24 ms |
23984 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
24 ms |
23984 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
29 ms |
23988 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
24064 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
25 ms |
24064 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
27 ms |
24064 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
24064 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |