;; F - Surrounded Nodes

(defparameter *modulus* (+ (expt 10 9) 7))

(defun main ()
  (let* ((N (read))  ; 頂点数
         (tree (read-tree N)))
    (princ (solve N tree))
    (fresh-line)))

; 自分が白: 2^(N - 1)
; (b1) 隣接する部分グラフがすべて白: 1
; (b2) 隣接する部分グラフのちょうど一つGに黒が含まれる: 2^size(G) - 1
; 自分がSに含まれる白頂点である確率:
; (2^(N - 1) - 1 - sum_G (2^size(G) - 1))/2^N
; 全頂点の合計:
; (N * 2^(N - 1) - N - (sum_G 2^size(G)) + 2 * (N - 1))/2^N

(defun solve (N tree)
  (destructuring-bind
    ; 各頂点の親と各部分木の頂点数
    (parent subtree-size) (make-rooted-tree 0 tree)
    (let* ((subgraph-size ; 部分グラフの頂点数のリスト
             (loop for v below N append ; 各頂点
               (loop for next in (aref tree v) collect ; vの隣接頂点
                 ; nextの向こう側の部分グラフの頂点数
                 (if (eql next (aref parent v)) ; vの親?
                     (- N (aref subtree-size v))
                     (aref subtree-size next)))))
           (numerator
             (+ (* N (mod-expt-2 (1- N)))
                N -2
                (- *modulus*
                   (reduce #'+ (mapcar #'mod-expt-2 subgraph-size))))))

    ; (2^N) * z == numerator mod *modulus* であるz
    ; *modulus*が素数なので 2^(*modulus* - 1) == 1 mod *modulus*
    (mod (* numerator (mod-expt-2 (- *modulus* 1 N))) *modulus*))))

(defun mod-expt-2 (p)
  "(mod (expt 2 p) *modulus*)を速く計算"
  (mod (reduce #'*
         (loop for i = p then (ash i -1) while (plusp i)
               for e = 2 then (mod (* e e) *modulus*)
               when (oddp i)
               collect e))
       *modulus*))

(defun make-rooted-tree (root tree)
  "頂点rootを根としてtreeの各頂点の親を決める. 部分木の大きさも計算する."
  (let* ((N (array-dimension tree 0)) ; 頂点数
         (parent (make-array N :initial-element nil)) ; 親
         (subtree-size (make-array N :initial-element nil))) ; 部分木の頂点数
    (labels
      ((dfs (stack)
         (when stack
           (let ((v (pop stack)))
             (if (aref subtree-size v)
               ; 帰りがけ
               (loop for next in (aref tree v) ; vの隣接頂点
                 unless (eql next (aref parent v)) ; 親以外
                   do (incf (aref subtree-size v)
                            (aref subtree-size next)))
               ; 行きがけ
               (loop
                 initially (push v stack) ; 帰りがけ用に残す
                           (setf (aref subtree-size v) 1)
                 for next in (aref tree v) ; vの隣接頂点
                 unless (eql next (aref parent v)) ; 親以外
                   do (push next stack)
                      (setf (aref parent next) v))))
           (dfs stack))))
      (dfs (list root))
      (list parent subtree-size))))

(defun read-tree (N)
  "N頂点の木をreadして作る. 頂点番号は0〜N-1"
  (let ((tree (make-array N))) ; 隣接リスト
    (loop for i below N do (setf (aref tree i) nil))
    (loop repeat (1- N)
      do (let ((a (read-fixnum))
               (b (read-fixnum)))
           (push (1- b) (aref tree (1- a)))
           (push (1- a) (aref tree (1- b)))))
    tree))

(defun read-fixnum (&optional (in *standard-input*))
  "readより速い整数専用read. 
   参考: 競技プログラミングでCommon Lispを使っている人と
   これから使うかもしれない人のために, @sansaqua
   https://qiita.com/sansaqua/items/0b6417cb541047e29da4"
  (loop with acc = 0
        with minus = nil
        with started = nil
        for byte = (read-byte in)
        if (<= 48 byte 57)
          do (setf acc (+ (* acc 10) (- byte 48)))
             (setf started t)
        else if started
          return (if minus (- acc) acc)
        else if (= byte 45)
          do (setf minus t)))

(main)


Measured memory_bytes: 80292