  Labeling schemes seek to assign a short label to each node in a network, so
that a function on two nodes can be computed by examining their labels alone.
For the particular case of trees, optimal bounds (up to low order terms) were
recently obtained for adjacency labeling [FOCS'15], nearest common ancestor
labeling [SODA'14], and ancestry labeling [SICOMP'06]. In this paper we obtain
optimal bounds for distance labeling. We present labels of size
$1/4\log^2n+o(\log^2n)$, matching (up to low order terms) the recent
$1/4\log^2n-O(\log n)$ lower bound [ICALP'16].
  Prior to our work, all distance labeling schemes for trees could be
reinterpreted as universal trees. A tree $T$ is said to be universal if any
tree on $n$ nodes can be found as a subtree of $T$. A universal tree with $|T|$
nodes implies a distance labeling scheme with label size $\log |T|$. In 1981,
Chung et al. proved that any distance labeling scheme based on universal trees
requires labels of size $1/2\log^2 n-\log n\cdot\log\log n+O(\log n)$. Our
scheme is the first to break this lower bound, showing a separation between
distance labeling and universal trees.
  The $\Theta(\log^2 n)$ barrier has led researchers to consider distances
bounded by $k$. The size of such labels was improved from $\log n+O(k\sqrt{\log
n})$ [WADS'01] to $\log n+O(k^2(\log(k\log n))$ [SODA'03] and then to $\log
n+O(k\log(k\log(n/k)))$ [PODC'07]. We show how to construct labels whose size
is $\min\{\log n+O(k\log((\log n)/k)),O(\log n\cdot\log(k/\log n))\}$. We
complement this with almost tight lower bounds of $\log n+\Omega(k\log(\log
n/(k\log k)))$ and $\Omega(\log n\cdot\log(k/\log n))$. Finally, we consider
$(1+\varepsilon)$-approximate distances. We show that the labeling scheme of
[ICALP'16] can be easily modified to obtain an $O(\log(1/\varepsilon)\cdot\log
n)$ upper bound and we prove a $\Omega(\log(1/\varepsilon)\cdot\log n)$ lower
bound.
