Solution (source code)

= Solution

A <graph state> has computational-basis expansion
$$
|G\rangle=\frac1{2^{|V|/2}}
\sum_{x\in\{0,1\}^{|V|}}
(-1)^{\sum_{(r,s)\in E}x_rx_s}|x\rangle.
$$
For the path $G_A$ with edges $(1,2)$ and $(2,3)$,
$$
\boxed{
|G_A\rangle=\frac1{\sqrt8}(
|000\rangle+|001\rangle+|010\rangle-|011\rangle
+|100\rangle+|101\rangle-|110\rangle+|111\rangle)}.
$$
For the triangle $G_B$, the extra edge $(3,1)$ changes the phase whenever $x_1=x_3=1$, giving
$$
\boxed{
|G_B\rangle=\frac1{\sqrt8}(
|000\rangle+|001\rangle+|010\rangle-|011\rangle
+|100\rangle-|101\rangle-|110\rangle-|111\rangle)}.
$$