Yes, the algorithm will still work for graphs with disconnected graphs. These distances will simply be represented by infinity.