Flattening is performed by first removing the loops and then bucket-sorting the edges
(as ordered pairs of vertex identifiers) lexicographically, which brings parallel
-edges together. The bucket sort uses two passes with $n$~buckets, so it takes
+edges together. The bucket sort uses two passes with $n_i$~buckets, so it takes
$\O(n_i+m_i)=\O(m)$.
\qed