Couldn’t you “just” create a nullable distance column and update anything that’s null and reachable by Bacon and set it to 1. Then update anyone still null and reachable by 1 to 2, etc. Then you have a materialized view of everyone’s Bacon number.
Not a generic solution of course, but seems extremely effective for the Bacon case.
Not a generic solution of course, but seems extremely effective for the Bacon case.