This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<ll, ll>    pll;
typedef pair<int, int>  pii;
#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0
#define X               first
#define Y               second
#define endl            '\n'
constexpr ll pw(ll a, ll b, ll mod) {
    return (!b    ? 1 :
            b & 1 ? a * pw(a * a % mod, b / 2, mod) % mod :
                    pw(a * a % mod, b / 2, mod));
}
constexpr int N   = 1e5 + 10;
int timer, E[N], ans;
vector<int> comp[N], R;
vector<pii> adj[N];
bitset<N> mark;
void preDFS(int u, int t) {
    comp[t].push_back(u);
    mark[u] = true;
    for (auto & e : adj[u]) if (!mark[e.X]) {
        preDFS(e.X, t);
    }
}
void pushDFS(int u, int p, int d) {
    E[u] = max(E[u], d);
    for (auto & e : adj[u]) if (e.X != p) {
        pushDFS(e.X, u, d + e.Y);
    }
}
int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
    for (int i = 0; i < m; i++) {
        adj[A[i]].emplace_back(B[i], T[i]);
        adj[B[i]].emplace_back(A[i], T[i]);
    }
    for (int i = 0; i < n; i++) if (!mark[i]) {
        preDFS(i, timer++);
    }
    for (int i = 0; i < timer; i++) {
        int u = comp[i][0], d = 0;
        for (int j : {0, 1, 2}) {
            pushDFS(u, -1, 0);
            for (int v: comp[i]) if (E[v] > d)
                u = v, d = E[v];
        }
        ans = max(ans, d);
        for (int v: comp[i]) if (E[v] < d)
            u = v, d = E[v];
        R.push_back(d);
    }
    sort(all(R));
    reverse(all(R));
    if (R.size() >= 2)
        ans = max(ans, R[0] + L + R[1]);
    if (R.size() >= 3)
        ans = max(ans, R[1] + 2 * L + R[2]);
    return ans;
}
Compilation message (stderr)
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:53:18: warning: unused variable 'j' [-Wunused-variable]
   53 |         for (int j : {0, 1, 2}) {
      |                  ^| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |