#include "bits/stdc++.h"
#include "shortcut.h"
using namespace std;
vector<pair<int,int>> adj[100001];
int ma = -1 , lol = -1;
void dfs(int i,int pr,int dep){
if(ma<dep){
ma = dep;
lol = i;
}
for(auto j:adj[i]){
if(j.first==pr)continue;
dfs(j.first,i,dep+j.second);
}
}
int cnt = 0;
long long oo = 1e18;
long long shortcut(int a,int b,int c){
vector<pair<long long,long long>> ne[cnt];
for(int i = 0;i<cnt;i++){
for(auto j:adj[i]){
ne[i].push_back(j);
}
if(i==a){
ne[i].push_back({b,c});
}if(i==b){
ne[i].push_back({a,c});
}
}
long long fin = 0;
for(int i = 0;i<cnt;i++){
long long dist[cnt];
for(int j = 0;j<cnt;j++)dist[j] = oo;
dist[i] = 0;
priority_queue<pair<long long,long long>> q;
q.push({0,i});
while(!q.empty()){
long long x = q.top().second , co = -q.top().first;
q.pop();
if(dist[x]<co)continue;
for(auto j:ne[x]){
if(dist[j.first]>co+j.second){
dist[j.first] = co+j.second;
q.push({-dist[j.first],j.first});
}
}
}
for(int j = 0;j<cnt;j++){
fin = max(fin,dist[j]);
}
}
return fin;
}
long long find_shortcut(int n,int l[], int d[], int c){
for(int i = 0;i<n;i++){
adj[i].clear();
}
for(int i = 1;i<n;i++){
adj[i-1].push_back({i,l[i-1]});
adj[i].push_back({i-1,l[i-1]});
}
cnt = n;
int pr[2*n+1] = {0};
for(int i = 0;i<n;i++){
if(d[i]){
pr[cnt] = i;
adj[cnt].clear();
adj[i].push_back({cnt,d[i]});
adj[cnt].push_back({i,d[i]});
cnt++;
}
}
dfs(0,-1,0);
ma = -1;
int f = lol;
dfs(lol,-1,0);
int s = lol;
vector<int> lol;
if(f>=n)f = pr[f];
if(s>=n)s = pr[s];
for(int i = max(0,f-1);i<min(n,f+2);i++)lol.push_back(i);
for(int i = max(0,s-1);i<min(n,s+2);i++)lol.push_back(i);
long long mi = oo;
for(int i = 0;i<n;i++){
for(auto j:lol){
mi = min(shortcut(i,j,c),mi);
mi = min(shortcut(i,j,c),mi);
}
}
return mi;
}
/*
int main(){
cout<<find_shortcut(4, {10,20,20},{0,40,0,30},10);
}*/
Compilation message
/usr/bin/ld: /tmp/ccUyPOVR.o: in function `main':
grader.cpp:(.text.startup+0x124): undefined reference to `find_shortcut(int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, int)'
collect2: error: ld returned 1 exit status