//Bismillahirrahmanirrahim
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< int,int > PII;
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=0;i<n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 2000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,co[li],vis[li],mx[li],A[li],B[li],T[li],mn;
int cev;
string s;
vector<PII> v[li];
vector<int> vec;
inline void dfs(int node,int ata){
vis[node]=1;
for(int i=0;i<(int)v[node].size();i++){
int go=v[node][i].fi;
if(go==ata)continue;
dfs(go,node);
co[node]=max(co[node],co[go]+v[node][i].se);
}
//~ cout<<node<<endl;
mx[node]=max(mx[node],co[node]);
}
inline void dfs1(int node,int ata,int der){
vis[node]=1;
multiset<int> st;
for(int i=0;i<(int)v[node].size();i++){
int go=v[node][i].fi;
if(go==ata)continue;
st.insert(co[go]+v[node][i].se);
}
int der1=der;
for(int i=0;i<(int)v[node].size();i++){
int go=v[node][i].fi;
if(go==ata)continue;
auto it=st.end();
it--;
if(*it==co[go]+v[node][i].se){
if(it!=st.begin()){
it--;
der1=max(der1,*it);
}
}
else der1=max(der1,*it);
dfs1(go,node,der1+v[node][i].se);
}
mx[node]=max(mx[node],der1);
cev=max(cev,mx[node]);
mn=min(mn,mx[node]);
}
int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
for(int i=0;i<m;i++){
v[A[i]].pb({B[i],T[i]});
v[B[i]].pb({A[i],T[i]});
}
FOR{
if(vis[i])continue;
mn=inf;
dfs(i,-1);
dfs1(i,-1,0);
vec.pb(mn);
}
sort(vec.begin(),vec.end());
reverse(vec.begin(),vec.end());
for(int i=1;i<(int)vec.size();i++){
cev=max(cev,vec[0]+vec[i]+l);
}
for(int i=2;i<(int)vec.size();i++){
cev=max(cev,vec[1]+vec[i]+2*l);
}
return cev;
}
int main() {
int N, M, L, i;
scanf("%d%d%d", &N, &M, &L);
for (i = 0; i < M; i++)
scanf("%d%d%d", &A[i], &B[i], &T[i]);
int answer = travelTime(N, M, L, A, B, T);
printf("%d\n", answer);
return 0;
}
Compilation message
dreaming.cpp: In function 'int main()':
dreaming.cpp:98:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
98 | scanf("%d%d%d", &N, &M, &L);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:100:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
100 | scanf("%d%d%d", &A[i], &B[i], &T[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/ccpybg6U.o: In function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccYP6PLI.o:grader.c:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status