#include<bits/stdc++.h>
using namespace std;
#define taskname "A"
#define pb push_back
typedef long double ld;
typedef long long ll;
const int maxn = 1e5 + 5;
int n , m,l;
ll now = 0;
vector<ll> v;
typedef pair<int,int> tpair;
#define mp make_pair
ll h[maxn];
ll h1[maxn];
vector<tpair> adj[maxn];
int vis[maxn];
ll res = 0;
void DFS(int u , int par){
vis[u] = 1;
multiset<ll,greater<ll>> s;
for(auto c : adj[u]){
if(c.first == par)continue;
DFS(c.first , u);
h[u] = max(h[u],h[c.first]+c.second);
s.insert(h[c.first]+c.second);
}
for(auto c : adj[u]){
if(c.first == par)continue;
s.erase(s.find(h[c.first]+c.second));
if(s.size())h1[c.first] = *s.begin();
s.insert(h[c.first]+c.second);
}
}
void DFS1(int u , int par , ll cur){
now = min(now,max(h[u],cur));
res = max(res,max(h[u],cur));
for(auto c : adj[u]){
if(c.first == par)continue;
DFS1(c.first,u,max(cur,h1[c.first])+c.second);
}
}
int travelTime(int N,int M,int L,int A[],int B[],int T[]){
ios_base::sync_with_stdio(0);
cin.tie(0);
// if(fopen(taskname".INP","r"))
// freopen(taskname".INP", "r",stdin) ,
// freopen(taskname".OUT", "w",stdout);
n = N;m = M;l = L;
for(int i = 1 ; i <= m ; ++i){
int u , v , w;u = A[i - 1] , v = B[i - 1] , w = T[i - 1];
adj[u].pb(mp(v,w));
adj[v].pb(mp(u,w));
}
for(int i = 0 ; i < n ; ++i){
if(vis[i] == 0){
now = 1e18;
DFS(i , -1);
DFS1(i , - 1, 0);
v.pb(now);
// cout << now << endl;
}
}
sort(v.begin(),v.end(),greater<ll>());
if(v.size() == 1)return max(res,v[0]);
else if(v.size() == 2)return max(v[0] + v[1] + l,res);
else return max(max(v[0]+v[1]+l,v[1]+v[2]+2*l),res);
}
Compilation message
/tmp/ccWPh72T.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status