/tmp/solutions/build/tree_diameter-slow.cpp:
    1|       |#include <common.h>
    2|       |prelude;
    3|       |
    4|       |namespace {
    5|       |
    6|       |constexpr int N = 5e5;
    7|       |
    8|       |struct edge {
    9|       |  int to;
   10|       |  int len;
   11|       |};
   12|       |
   13|       |int pa[N];
   14|       |std::vector<edge> ch[N];
   15|       |
   16|   779k|def tree_diameter(int u, int p) -> std::pair<u64, int> {
   17|   779k|  pa[u] = p;
   18|   779k|  std::pair<u64, int> ans{0, u};
   19|  1.55M|  for (let[v, len] : ch[u]) {
                     ^779k
  ------------------
  |  Branch (19:20): [True: 66.67%, False: 33.33%]
  ------------------
   20|  1.55M|    if (v != p) {
  ------------------
  |  Branch (20:9): [True: 50.00%, False: 50.00%]
  ------------------
   21|   779k|      def res = tree_diameter(v, u);
   22|   779k|      res.first += len;
   23|   779k|      ans = std::max(ans, res);
   24|   779k|    }
   25|  1.55M|  }
   26|   779k|  return ans;
   27|   779k|}
   28|       |
   29|       |} // namespace
   30|       |
   31|      1|int main() {
   32|      1|  rd rd;
   33|      1|  wt wt;
   34|      1|  int n = rd.uh();
   35|   389k|  for (int i = 1; i < n; ++i) {
                                       ^389k
  ------------------
  |  Branch (35:19): [True: 100.00%, False: 0.00%]
  ------------------
   36|   389k|    int a = rd.uh();
   37|   389k|    int b = rd.uh();
   38|   389k|    int c = rd.uw();
   39|   389k|    ch[a].emplace_back(b, c);
   40|   389k|    ch[b].emplace_back(a, c);
   41|   389k|  }
   42|      1|  let[_, u] = tree_diameter(0, -1);
   43|      1|  let[d, v] = tree_diameter(u, -1);
   44|      1|  int c = 0;
   45|     50|  for (int i = v; i != -1; i = pa[i]) ++c;
                                         ^49        ^49
  ------------------
  |  Branch (45:19): [True: 98.00%, False: 2.00%]
  ------------------
   46|      1|  wt.ud(d);
   47|      1|  wt.uw(c);
   48|     50|  for (int i = v; i != -1; i = pa[i]) wt.uw(i);
                                         ^49        ^49
  ------------------
  |  Branch (48:19): [True: 98.00%, False: 2.00%]
  ------------------
   49|      1|#ifdef LOCAL
   50|   389k|  for (int i = 0; i < n; ++i) ch[i].clear();
                                       ^389k^389k
  ------------------
  |  Branch (50:19): [True: 100.00%, False: 0.00%]
  ------------------
   51|      1|#endif
   52|      1|  return 0;
   53|      1|}