#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> pp;
typedef vector<pp> vec;
typedef vector<vec> mat;
#define pb push_back
int N;
int subsz[100000],subsz2[100000];
int vi[100000],vi2[100000];
int Max,len[100000],ans;
bool chk[100000];
vec s;
mat path;
void dfs(int v){
chk[v]=1;
for(int i=0;i<path[v].size();i++){
int u=path[v][i].first;
int c=path[v][i].second;
if(chk[u])continue;
dfs(u);
int t=subsz[u]+c;
if(subsz[v]<t){
subsz2[v]=subsz[v];vi2[v]=vi[v];
subsz[v]=t;vi[v]=u;
}else if(subsz2[v]<t){
subsz2[v]=t;vi2[v]=u;
}
}
// printf("%d : (%d,%d), (%d,%d)\n",v,subsz[v],vi[v],subsz2[v],vi2[v]);
}
void dfs2(int v,int h){
Max=min(Max,max(h,max(subsz[v],subsz2[v])));
ans=max(ans,max(h+subsz[v],subsz[v]+subsz2[v]));
chk[v]=0;
for(int i=0;i<path[v].size();i++){
int u=path[v][i].first;
int c=path[v][i].second;
if(!chk[u])continue;
if(u==vi[v]){
dfs2(u,max(h,subsz2[v])+c);
}else if(u==vi2[v]){
dfs2(u,max(h,subsz[v])+c);
}
}
}
int travelTime(int N_, int M, int L, int A[], int B[], int T[]) {
N=N_;
path.assign(N+1,vec());
for(int i=0;i<M;i++){
path[A[i]].pb(pp(B[i],T[i]));
path[B[i]].pb(pp(A[i],T[i]));
}
for(int i=0;i<N;i++){
if(!chk[i]){
dfs(i);
}
}
for(int i=0;i<N;i++){
if(chk[i]){
Max=1e9;
dfs2(i,0);
len[i]=Max;
s.pb(pp(len[i],i));
}
}
sort(s.begin(),s.end());
/*
for(int i=0;i<s.size();i++){
printf("(%d,%d) ",s[i].first,s[i].second);
}
*/
if(s.size()==1)return max(ans,s[0].first);
return max(ans,s[s.size()-1].first+s[s.size()-2].first+L);
}
Compilation message
dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:20:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<path[v].size();i++){
~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int, int)':
dreaming.cpp:40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<path[v].size();i++){
~^~~~~~~~~~~~~~~
/tmp/ccSTo7fZ.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status