Explanation
Assume there is some hard route that goes from vertex to vertex . Let the node that the path from to and the furthest node from the hard route meet be node . Use rerooting DP to calculate the hardest route and the number of such hardest routes for every node .
Implementation
Time Complexity:
C++
#include <bits/stdc++.h>using namespace std;using ll = long long;int main() {int n;cin >> n;vector<vector<int>> adj(n);for (int i = 1; i < n; i++) {int x, y;
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!