So let the distance be d, the downstream speed be d/A, the upstream speed be d/B, and the water flow speed be equal to v=(d/A-d/B)/2.
So the drift time is equal to d/v = 2/(1/a-1/b) = 2ab/(b-a).