  We consider the shape optimization problem $$\min\big\{{\mathcal E}(\Gamma)\
:\ \Gamma\in{\mathcal A},\ {\mathcal H}^1(\Gamma)=l\ \big\},$$ where ${\mathcal
H}^1$ is the one-dimensional Hausdorff measure and ${\mathcal A}$ is an
admissible class of one-dimensional sets connecting some prescribed set of
points ${\mathcal D}=\{D_1,\dots,D_k\}\subset{\mathbb R}^d$. The cost
functional ${\mathcal E}(\Gamma)$ is the Dirichlet energy of $\Gamma$ defined
through the Sobolev functions on $\Gamma$ vanishing on the points $D_i$. We
analyze the existence of a solution in both the families of connected sets and
of metric graphs. At the end, several explicit examples are discussed.
