{-# 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,Int)
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,0)
    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
        ))
        (si * sj)

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

solve :: Int -> Int -> V.Vector (Int,Int) -> V.Vector Int
solve n m abs = unsafePerformIO $ V.freeze $ (\(_,_,acc) -> acc) $ V.foldr go (group, 0, unsafePerformIO $ VM.replicate m 0) abs
  where
    go (a,b) (uf,k,acc) =
      let (uf'@(UnionFind (!elems,!sizes)),d) = unionUF uf a b in
      let prev = if k == 0 then 0 else unsafePerformIO $ VM.read acc (k-1) in
        (uf', k+1, unsafePerformIO $ (VM.write acc k (prev+d) >> return acc))

    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)

  let solutions =  solve (nm V.! 0) (nm V.! 1) abs
  let nC2 = comb2 $ nm V.! 0

  mapM_ (print . (nC2 -) . (solutions V.!)) [nm V.! 1 - 2, nm V.! 1 - 3 .. 0]
  print nC2
