#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
using ll = long long;
const int INF = 1e9 + 7;
const int MOD = 998244353;
const int MAXN = 1e5;
int n;
int dp[MAXN + 1];
vector<vector<pair<int, int>>> adj;
int dfs(int k, int p)
{
if (!dp[k])
{
dp[k] = 1;
for (pair<int, int> i : adj[k])
if (i.F != p)
dp[k] += dfs(i.F, k);
return dp[k];
}
int mx = 0;
for (pair<int, int> i : adj[k])
{
if (i.F == p)
continue;
if (dp[i.F] > dp[mx])
mx = i.F;
}
if (dp[mx] <= (n >> 1))
return k;
return dfs(mx, k);
}
int dfs2(int k, int p)
{
int res = 0;
for (pair<int, int> i : adj[k])
if (i.F != p)
res = max(res, i.S + dfs2(i.F, k));
return res;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
adj.resize(N + 1);
for (int i = 0; i < M; i++)
{
A[i]++; B[i]++;
adj[A[i]].emplace_back(B[i], T[i]);
adj[B[i]].emplace_back(A[i], T[i]);
}
vector<int> v;
for (int i = 1; i <= N; i++)
if (!dp[i])
{
dfs(i, i);
n = dp[i];
int x = dfs(i, i);
v.push_back(dfs2(x, x));
}
sort(v.begin(), v.end(), greater<int>());
return v[0] + v[1] + L;
}
Compilation message
/usr/bin/ld: /tmp/ccNSjeQh.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status