Algorithm works correctly (as tested on 3 pairs of trees)\!