#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll MOD = 1000000007;
const int MAXN = 100010;
vector<pii> adj[MAXN];
int sub[MAXN], diam, m1[MAXN], m2[MAXN];
bool vis[MAXN];
void dfs(int node){
vis[node] = 1;
for(auto x: adj[node]){
if(vis[x.fi])continue;
dfs(x.fi);
sub[node] += sub[x.fi] + x.se;
}
}
int reroot(int node){
vis[node] = 1;
for(auto x: adj[node]){
if(sub[x.fi]+x.se>=m1[node]){
m2[node] = m1[node];
m1[node] = sub[x.fi]+x.se;
}else if(sub[x.fi]+x.se > m2[node]){
m2[node] = sub[x.fi]+x.se;
}
}
diam = max(diam, m1[node] + m2[node]);
int ans = m1[node];
for(auto x: adj[node]){
if(vis[x.fi])continue;
if(m1[node] == sub[x.fi]+x.se)sub[node] = m2[node];
else sub[node] = m1[node];
ans = max(ans,reroot(x.fi));
}
return ans;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
for(int i = 0; i < M; i++){
adj[A[i]].pb({B[i],T[i]});
adj[B[i]].pb({A[i],T[i]});
}
int k,m=0,mm=0, mmm = 0;
for(int i = 0; i < N; i++)if(!vis[i])dfs(i);
for(int i = 0; i < N; i++)vis[i] = 0;
for(int i = 0; i < N; i++)if(!vis[i]){
k = reroot(i);
if(k >= m){
mmm = mm; mm = m; m = k;
}else if(k >= mm){
mmm = mm; mm = k;
}else if(k > mmm){
mmm = k;
}
}
return max({2*L+mmm+mm, L + m+mm, diam});
}
Compilation message
/tmp/ccTGoc9I.o: In function `main':
grader.c:(.text.startup+0xa7): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status