Graphs, spanning trees and divergence-free finite elements in domains of general topology