// Ignut
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 123;
const int MAXN = 1e5 + 123;
vector<pair<int, int>> tree[MAXN];
int dist[MAXN];
void dfs(int v, int par, int d) {
dist[v] = d;
for (auto [to, w] : tree[v])
if (to != par)
dfs(to, v, d + 1);
}
void FindDist(int source) {
dfs(source, -1, 0);
}
bool used[MAXN];
vector<int> comp;
void dfs0(int v, int par = -1) {
used[v] = true;
comp.push_back(v);
for (auto [to, w] : tree[v])
if (to != par)
dfs0(to, v);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for (int i = 0; i < N; i ++) {
tree[i].clear();
used[i] = false;
}
for (int i = 0; i < M; i ++) {
tree[A[i]].push_back({B[i], T[i]});
tree[B[i]].push_back({A[i], T[i]});
}
vector<int> c;
for (int i = 0; i < N; i ++) {
if (used[i]) continue;
comp.clear();
dfs0(i);
int ctr = 0, maxD = INF;
for (int v : comp) {
FindDist(v);
int md = 0;
for (int u : comp) md = max(md, dist[u]);
if (md < maxD) {
ctr = v;
maxD = md;
}
}
c.push_back(ctr);
}
if (c.size() == 2) {
tree[c[0]].push_back({c[1], L});
tree[c[1]].push_back({c[0], L});
}
int res = 0;
for (int i = 0; i < N; i ++) {
FindDist(i);
for (int j = 0; j < N; j ++) res = max(res, dist[j]);
}
return res;
}
Compilation message
/usr/bin/ld: /tmp/ccgLOAlv.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status