#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
const int N=1e5+5;
vector<pair<int,int>> g[N];
int used[N],d[N];
pair<int,int> par[N];
vector<int> vec;
int ans=0;
int D,f;
void dfs(int x, int p){
used[x]=1;
if(p==x){
d[x]=0;
D=0,f=x;
}
else{
if(d[x]>D){
D=d[x];
f=x;
}
}
for(auto it: g[x]){
if(it.fr==p) continue;
d[it.fr]=it.sc+d[x];
par[it.fr]={x,it.sc};
dfs(it.fr,x);
}
}
void find(int x){
dfs(x,x);
int a=f;
dfs(a,a);
int b=f;
ans=max(ans,D);
if(a==b){
vec.push_back(0);
return;
}
int cur=b,d=0;
while(true){
int last=d;
d+=par[cur].sc;
cur=par[cur].fr;
if(2*d>=D){
vec.push_back({D-last});
return;
}
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i=0;i<M;i++){
g[A[i]].push_back({B[i],T[i]});
g[B[i]].push_back({A[i],T[i]});
}
for(int i=0;i<N;i++){
if(!used[i]){
find(i);
}
}
sort(vec.rbegin(),vec.rend());
if(vec.size()>1)
ans=max(ans,vec[0]+vec[1]+L);
if(vec.size()>2)
ans=max(ans,vec[1]+vec[2]+L+L);
return ans;
}
int main(){
int n,m,l;cin>>n>>m>>l;
int a[m]{},b[m]{},t[m]{};
for(int i=0;i<m;i++){
cin>>a[i]>>b[i]>>t[i];
}
cout<<travelTime(n,m,l,a,b,t);
}
Compilation message
/usr/bin/ld: /tmp/ccCmHfJS.o: in function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cczVhWCS.o:grader.c:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status