import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import qualified Data.ByteString.Char8 as C
import Data.List

main = sub <$> get >>= put

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines <$> C.getContents

sub ([n,k,_]:es) = sol n (splitAt k es)

put = putStrLn . unwords . fmap show

sol n (roads,rails) = runST $ do
  ufroad <- newUnionFind n
  forM roads (unionUF ufroad) 
  ufrail <- newUnionFind n
  forM rails (unionUF ufrail)
  let connected i j = liftM2 (&&) (sameUF ufroad i j) (sameUF ufrail i j)
  forM [1..n] $ (length <$>) . flip filterM [1..n] . connected

-- | Union-Find
data UnionFind s = UnionFind {ids:: STUArray s Int Int, szs:: STUArray s Int Int}

newUnionFind :: Int -> ST s (UnionFind s)
newUnionFind n = liftM2 UnionFind (newListArray (1,n) [1..n]) (newArray (1,n) 1)

sameUF :: UnionFind s -> Int -> Int -> ST s Bool
sameUF uf p q = liftM2 (==) (rootUF uf p) (rootUF uf q)

rootUF :: UnionFind s -> Int -> ST s Int
rootUF uf i = do
  ix <- readArray (ids uf) i
  if ix == i
    then return i
    else do
      writeArray (ids uf) i =<< readArray (ids uf) ix
      rootUF uf ix

unionUF :: UnionFind s -> [Int] -> ST s ()
unionUF uf [p,q] = do
  i <- rootUF uf p
  j <- rootUF uf q
  szi <- readArray (szs uf) i
  szj <- readArray (szs uf) j
  if szi < szj
    then do
      writeArray (ids uf) i j
      writeArray (szs uf) j (szi+szj)
      writeArray (szs uf) i 0
    else do
      writeArray (ids uf) j i
      writeArray (szs uf) i (szj+szi)
      writeArray (szs uf) j 0
