Solution (source code)

= Solution

For an open cover $X=U\cup V$, the <Mayer–Vietoris theorem> gives the <long exact sequence>
$$
\cdots\to H_k(U\cap V)\xrightarrow{(i_*,-j_*)}H_k(U)\oplus H_k(V)
\xrightarrow{k_*+\ell_*}H_k(X)\xrightarrow{\delta}H_{k-1}(U\cap V)\to\cdots.
$$
It ends in $H_0(U\cap V)\to H_0(U)\oplus H_0(V)\to H_0(X)\to0$. To prove it, let $C_*^{U,V}(X)$ be the subcomplex generated by singular simplices lying wholly in $U$ or wholly in $V$. There is a <short exact sequence> of chain complexes
$$
0\to C_*(U\cap V)\xrightarrow{c\mapsto(c,-c)}C_*(U)\oplus C_*(V)
\xrightarrow{(a,b)\mapsto a+b}C_*^{U,V}(X)\to0.
$$
Exactness follows from the singular-<simplex> bases: the intersection of the two chain subgroups consists exactly of simplices lying in both sets. The <small-chain locality theorem for singular homology> says the inclusion of this small-<chain complex> into $C_*(X)$ induces an isomorphism on <homology>; <barycentric subdivision> is its standard justification. The <long exact sequence> of a <short exact sequence> of chain complexes now proves the theorem. For a <homological cycle> represented as $a+b$, the connecting map is $[a+b]\mapsto[\partial a]$, since $\partial a=-\partial b$ lies in the intersection. This also identifies the displayed maps and their signs.

For the glued solid tori, use open collar enlargements of the two halves. Each retracts to a circle; the overlap retracts to their boundary <torus>. Thus the halves have $H_0=H_1=\mathbb Z$ and higher <homology> zero, while the overlap has $H_0=H_2=\mathbb Z$ and $H_1=\mathbb Z^2$. In the overlap choose <longitude> and <meridian> generators. The <meridian> bounds a disk in each <solid torus> and the <longitude> generates each first <homology>, so the map on $H_1$ is
$$
(a,b)\longmapsto(a,-a).
$$
Its kernel is the <meridian> copy of $\mathbb Z$ and its cokernel is $\mathbb Z$. The map on $H_0$ is the injective map $z\mapsto(z,-z)$. Exactness therefore gives $H_2(X)=\mathbb Z$ and $H_1(X)=\mathbb Z$. The preceding segment is $0\to H_3(X)\to H_2(U\cap V)\to0$, giving $H_3(X)=\mathbb Z$. <Connectedness> gives $H_0(X)=\mathbb Z$, and all higher groups vanish. Hence
$$
\boxed{H_k(X)=\mathbb Z\ (k=0,1,2,3),\qquad H_k(X)=0\ (k\ge4)}.
$$
As a geometric check, the identity boundary gluing identifies the product with $S^1\times(D^2\cup_{S^1}D^2)=S^1\times S^2$.