Two different graph densities: $|E|/|V|$ and $|E|/(|V|-1)$
Here is a very slow algorithm, but it handles more general cases, like when density is defined as $d_\beta(G) = \frac{m(G)}{n(G)-\beta}$.
Let $f$ be a submodular function, $g$ be a modular function strictly larger than $0$. The min ratio problem $\min_S f(S)/g(S)$ can be solved in polynomial time. Indeed, use the standard to convert min ratio problem to parametric search problem with linear terms.
Consider we have input graph $G=(V,E)$.
For $d_\beta$ density, fix a set $T$ of size $k = \lfloor \beta \rfloor + 1$, and define $f_T:2^{V-T} \to \mathbb{R}$ as $f_T(S) = -m(G[T\cup S])$, and define $g_T:2^{V-T} \to \mathbb{R}_{&gt;0}$ as $g_T(S) = |S|+|T|$. You can check $f$ is submodular through a counting argument.
Consider the optimum $T$ and $S$ for $$\min_{T:|T|=k, T\subset V} \min_{S:S\subset V\setminus T} f_T(S)/g_T(S).$$ Let $T$ and $S$ be the optimum of the problem. The densest subgraph is $G[T\cup S]$.
Running time is $O(n^k)$ calls to the min ratio oracle. Maybe faster algorithm exists, be nice to avoid that $k$ in the exponent.