Relationship between scattering matrix and spectrum of quantum graphs