These marginals can be efficiently pre-computed and form the "inside" table of the famous Inside-Outside algorithm.
in our setting, trees come in pairs, and their joint probability crucially depends on their alignment.