We study the spectra of quantum graphs with the method of trace identities
(sum rules), which are used to derive inequalities of Lieb-Thirring,
Payne-P\'olya-Weinberger, and Yang types, among others. We show that the sharp
constants of these inequalities and even their forms depend on the topology of
the graph. Conditions are identified under which the sharp constants are the
same as for the classical inequalities; in particular, this is true in the case
of trees. We also provide some counterexamples where the classical form of the
inequalities is false.