Binary lifting can be used to find the heaviest edge in the path from node to . Therefore, we only need to find the heaviest edge from to and to .
Implementation
Time Complexity:
C++
#include <bits/stdc++.h>using namespace std;using ll = long long;const int MAXN = 2e5;const int MAXL = 20; // approximately maximum log// for euler-tourarray<int, MAXN> enter_time, exit_time, depth;
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!