Purpose
Find the diameter of a tree.
Time Complexity
Depends
Usage
Declaration
auto res = getGraphDiameter(g,s);Get the diameter using res.cost. Get the vertices forming the diameter using res.u and res.v.
Implementation
struct getGraphDiameter_return { int u, v, cost;};getGraphDiameter_return getGraphDiameter(DirectedGraph &_g) { auto u = getFarthestVertex(_g, 0); auto v = getFarthestVertex(_g, u.v); return {u.v, v.v, v.cost};}