#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 ans,len[100000];
bool chk[100000];
vec s;
mat path;
void dfs(int v,int p){
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(u==p)continue;
dfs(u,v);
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;
}
}
}
void dfs2(int v,int p,int h){
ans=min(ans,max(h,max(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(u==p)continue;
if(u==vi[v]){
dfs2(u,v,max(h,subsz2[v])+c);
}else if(u==vi2[v]){
dfs2(u,v,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,i);
}
}
for(int i=0;i<N;i++){
if(chk[i]){
ans=1e9;
dfs2(i,i,0);
len[i]=ans;
s.pb(pp(len[i],i));
}
}
sort(s.begin(),s.end());
if(s.size()==1)return s[0].first;
return s[s.size()-1].first+s[s.size()-2].first+L;
}
Compilation message
dreaming.cpp: In function 'void dfs(int, 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, int)':
dreaming.cpp:38:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<path[v].size();i++){
~^~~~~~~~~~~~~~~
/tmp/cc40k7C4.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status