CSES - Tree Distances I
Authors: Nathan Wang, Benjamin Qi
Solution 1
Described in CPH 14.3.
This section is not complete.
Feel free to file a request to complete this using the "Contact Us" button.
Solution 2
Compute a diameter of the tree as described by algorithm 2 here. Once we have a diameter , output for each node .
1#include <bits/stdc++.h>23using namespace std;45// dist[0][i] = distance from node a to node i6// dist[1][i] = distance from node b to node i7int dist[2][200000];8vector<int> adj[200000];910int dfs(int u, int p, int d, int i) {
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!