Spectral flow is a complete invariant for detecting bifurcation of critical points