#include<bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
const int N = int(1e5) + 7;
int dis[N], vis[N], trade[N], cc, d, _mx, mx;
vector<pii> a[N];
vector<int> r;
void DFS(int u, int lim) {
vis[u] = lim; d = max(d, dis[u]);
if(mx == -1 || dis[u] > dis[mx]) mx = u;
for(pii ed: a[u]) {
if(vis[ed.fi] < lim) {
dis[ed.fi] = dis[u] + ed.se;
trade[ed.fi] = u;
DFS(ed.fi, lim);
}
}
}
int Find(int s, int t)
{
int dist = dis[t], res = dis[t];
while(t != s) {
res = min(res, max(dis[t], dist - dis[t]));
t = trade[t];
}
return res;
}
int travelTime(int n, int m, int l, int s[], int t[], int w[])
{
for(int i = 0; i < m; ++i) a[s[i]].pb(t[i], w[i]), a[t[i]].pb(s[i], w[i]);
cc = d = 0;
fill(vis, vis + n, 0);
for(int i = 0; i < n; ++i) {
if(!vis[i]) {
dis[i] = 0, mx = i, DFS(i, 1);
dis[_mx = mx] = 0, DFS(_mx, 2);
r.pb(Find(_mx, mx));
++cc;
}
}
sort(r.begin(), r.end(), greater<int>());
if(cc == 1) return d;
else if(cc == 2) return r[0] + r[1] + l;
return max(r[1] + r[2] + 2 * l, r[0] + r[1] + l);
}
//
//int _n, _m, _l, _a[N], _b[N], _t[N];
//
//int main()
//{
// ios_base::sync_with_stdio(0);
// cin.tie(0), cout.tie(0);
// if(fopen("test.inp", "r")) {
// freopen("test.inp", "r", stdin);
// freopen("test.out", "w", stdout);
// }
// cin >> _n >> _m >> _l;
// for(int i = 0; i < _m; ++i) cin >> _a[i] >> _b[i] >> _t[i];
// cout << travelTime(_n, _m, _l, _a, _b, _t);
//}
Compilation message
/tmp/ccbNqYVm.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status