title: Maximum distance of two tree nodes with same color
body: <p>Given a tree with <code>N</code> vertices where each edge has weight <code>1</code>. The nodes are colored with <code>C</code> colors. We wish to find, for each color, the maximum shortest distance between two nodes of that color. </p>
  
  <p>I can build a sparse table and then find LCA of two nodes in <code>O(log n)</code>. Then check all pairs of same color. This gives <code>O(n^2 log n)</code>. Is it possible to do better than this?</p>