{-# LANGUAGE BangPatterns #-}
import Control.Arrow (second)
import Control.Monad
import Control.Monad.Fix
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as B
import System.IO.Unsafe

newtype UnionFind = UnionFind (VM.IOVector Int, VM.IOVector Int)

findUF :: UnionFind -> Int -> Int
findUF (UnionFind (elems,_)) k = fix (\f (elems,k,path) ->
  case unsafePerformIO (VM.read elems k) of
    n | n == k -> 
      unsafePerformIO (forM_ path $ \p -> VM.write elems p n) `seq`
      n
    n -> f (elems,n,n:path)
  ) (elems,k,[k])

sizeUF :: UnionFind -> Int -> Int
sizeUF (UnionFind (_,sizes)) i = unsafePerformIO (VM.read sizes i)

unionUF :: UnionFind -> Int -> Int -> UnionFind
unionUF uf@(UnionFind (elems,sizes)) i j =
  let !pi = findUF uf i; !pj = findUF uf j in
  let !si = sizeUF uf pi; !sj = sizeUF uf pj in
  let !sij = si + sj in
  if pi == pj
    then uf
    else
      UnionFind (
        unsafePerformIO $ (if si < sj then VM.write elems pi pj else VM.write elems pj pi) >> return elems,
        unsafePerformIO $ (if si < sj then VM.write sizes pj sij >> VM.write sizes pi 0 else VM.write sizes pi sij >> VM.write sizes pj 0) >> return sizes
      )

solve :: Int -> Int -> V.Vector (Int,Int) -> V.Vector Int
solve n m abs = V.drop 1 $ V.reverse $ V.cons nC2 $ unsafePerformIO $ V.freeze $ (\(_,_,acc) -> acc) $ V.foldl' go (group, 0, unsafePerformIO $ VM.replicate m 0) (V.reverse abs)
  where
    go (uf,k,acc) (a,b) =
      let uf'@(UnionFind (!elems,!sizes)) = unionUF uf a b in
      let !n = V.sum $ V.map comb2 $ unsafePerformIO (V.freeze sizes) in
        (uf', k+1, unsafePerformIO $ (VM.write acc k (nC2 - n) >> return acc))

    comb2 k = k * (k - 1) `div` 2
    nC2 = comb2 n

    group :: UnionFind
    group = UnionFind (unsafePerformIO $ V.thaw $ V.enumFromN 0 n, unsafePerformIO $ VM.replicate n 1)

main = do
  let readInt = fmap (second B.tail) . B.readInt
  let readJustInt = fst . (\(Just x) -> x) . B.readInt

  nm <- V.unfoldrN 2 readInt <$> B.getLine
  abs <- V.replicateM (nm V.! 1) ((\vec -> (vec V.! 0 - 1, vec V.! 1 - 1)) . V.unfoldrN 2 readInt <$> B.getLine)
  V.mapM_ print $ solve (nm V.! 0) (nm V.! 1) abs
