Let \({\mathcal {M}}_{\mathcal {D}}\) be the dyadic maximal operator on \({\mathbb {R}}^n\) . The paper contains the identification of the best constant in the two-weight estimate \(\begin{aligned} \Vert {\mathcal {M}}_{\mathcal {D}}f\Vert _{L^p(w)}\le C_{p,\sigma ,w}\Vert f\Vert _{L^p(\sigma ^{1-p})} \end{aligned}\) under the assumption that the pair \((\sigma ,w)\) of weights satisfies an appropriate bump condition. The result is shown to be true in the larger context of abstract probability spaces equipped with a tree-like structure.