In this paper we consider 2-step nilpotent Lie algebras, Lie groups and nilmanifolds associated with graphs. We present a combinatorial construction of the second cohomology group for these Lie algebras. This enables us to characterize those graphs giving rise to symplectic or contact nilmanifolds. (C) 2009 Elsevier B.V. All rights reserved.