A pairing between graphs and trees