{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

black :: Int
black = 0
white :: Int
white = 1

solve :: Int -> [(Int,Int)] -> Int
solve bN xys = theFunc (black,1) `mAdd` theFunc (white,1)
  where

  children = vCreate (bN+1) [] act

  act vec = do
    forM_ xys $ \(x,y) -> do
      VM.modify vec (x:) y
      VM.modify vec (y:) x
    mkRt 1 (-1)
    return vec
      
      where
      mkRt j parent = do
        cs <- VM.read vec j
        let newCs = filter (/= parent) cs
        VM.write vec j newCs
        forM_ newCs $ \c -> mkRt c j

  enc (color, i) = color * (bN+1) + i

  theFunc = func_memo enc (memovec enc (2*(bN+1)) mf [(black,1), (white,1)])

  mf rc (color,i)
    | color == black = mProdM [rc (white, j) | j <- cldrn]
    | color == white = mProdM [mAdd <$> rc (white, j) <*> rc (black, j)
                              | j <- cldrn]
    where cldrn = children V.! i
                     
vCreate :: Int -> a ->
           (forall s. VM.MVector s a -> ST s (VM.MVector s a)) ->
           V.Vector a
vCreate n init act = V.create $ do
  vec <- VM.replicate n init
  act vec
  return vec

mPrime = 10^9 + 7

mAdd :: Int -> Int -> Int
mAdd x y = let w = x + y in if w < mPrime then w else w - mPrime

mMul :: Int -> Int -> Int
mMul x y = (x * y) `mod` mPrime

mProdM :: Monad m => [m Int] -> m Int
mProdM mxs = sub 1 mxs where
  sub !acc [] = return acc
  sub !acc (mx:mxs) = do
    x <- mx
    sub (acc `mMul` x) mxs

memovec :: forall a d. (VU.Unbox a, Show a, Show d) =>
           (d -> Int) -> Int -> 
           (forall m. Monad m => (d -> m a) -> d -> m a) ->
           [d] -> VU.Vector a
memovec encode size mf ds = VU.create $ do
  vec <- VUM.new size
  flags <- VUM.replicate size False
  mapM_ (calc vec flags) ds
  return vec
  where
    calc vec flags d = do
      fv <- VUM.read flags (encode d)
      if fv then VUM.read vec (encode d)
        else do
        val <- mf (calc vec flags) d
        VUM.write vec   (encode d) val
        VUM.write flags (encode d) True
        return val

func_memo :: VU.Unbox a => (d->Int) -> VU.Vector a -> d -> a
func_memo encode vecV d = vecV VU.! (encode d)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_bN]:remLines1 = remLines0
      bN = readBInt bs_bN
      xys = map (\[x1,x2] -> (readBInt x1,readBInt x2)) remLines1
  in solve bN xys

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents
