AC solution

AC but code is not great. Running dijsktra twice and not sure ATM how to reduce it to one.