AtCoder Beginner Contest 149 - Surrounded Nodes

Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N).
Now, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let S be the smallest subtree (connected subgraph) of T containing all the vertices painted black. (If no vertex is painted black, S is the empty graph.)
Let the holeyness of S be the number of white vertices contained in S. Find the expected holeyness of S.
Since the answer is a rational number, we ask you to print it \bmod 10^9+7, as described in Notes.

-----Notes-----
When you print a rational number, first write it as a fraction \frac{y}{x}, where x, y are integers, and x is not divisible by 10^9 + 7
(under the constraints of the problem, such representation is always possible).
Then, you need to print the only integer z between 0 and 10^9 + 6, inclusive, that satisfies xz \equiv y \pmod{10^9 + 7}.

-----Constraints-----
 - 2 \leq N \leq 2 \times 10^5
 - 1 \leq A_i,B_i \leq N
 - The given graph is a tree.

-----Input-----
Input is given from Standard Input in the following format:
N
A_1 B_1
:
A_{N-1} B_{N-1}

-----Output-----
Print the expected holeyness of S, \bmod 10^9+7.

-----Sample Input-----
3
1 2
2 3

-----Sample Output-----
125000001

If the vertices 1, 2, 3 are painted black, white, black, respectively, the holeyness of S is 1.
Otherwise, the holeyness is 0, so the expected holeyness is 1/8.
Since 8 \times 125000001 \equiv 1 \pmod{10^9+7}, we should print 125000001.

Difficulty: MEDIUM_HARD

Starter code:

Solutions:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
ans = 0

def main(n, ab):
	ki = [[] for _ in range(n)]
	for (a, b) in ab:
		(a, b) = (a - 1, b - 1)
		ki[a].append(b)
		ki[b].append(a)
	mod = 10 ** 9 + 7
	n2 = [1]
	for i in range(n):
		n2.append(n2[-1] * 2 % mod)

	def dfs1(v, p):
		ret = 0
		nonlocal ans
		ans += n2[n - 1] - 1
		for nv in ki[v]:
			if nv == p:
				continue
			x = dfs1(nv, v)
			ans -= n2[x] - 1
			ans -= n2[n - x] - 1
			ret += x
		ans %= mod
		return ret + 1
	dfs1(0, -1)
	allpat = pow(2, n, mod)
	nonlocal ans
	ans *= pow(allpat, mod - 2, mod)
	return ans % mod
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
print(main(n, ab))


import sys
input = sys.stdin.readline
n = int(input())
ab = [list(map(int, input().split())) for i in range(n - 1)]
graph = [[] for i in range(n + 1)]
deg = [0] * (n + 1)
for (a, b) in ab:
	graph[a].append(b)
	graph[b].append(a)
	deg[a] += 1
	deg[b] += 1
stack = []
root = -1
for i in range(1, n + 1):
	if deg[i] == 1:
		stack.append(i)
	elif root == -1:
		root = i
deg[root] += 1
dp = [[] for i in range(n + 1)]
num = [0] * (n + 1)
while stack:
	x = stack.pop()
	if dp[x]:
		num[x] = sum(dp[x]) + 1
	else:
		num[x] = 1
	for y in graph[x]:
		if deg[y] > 1:
			dp[y].append(num[x])
			deg[y] -= 1
			if deg[y] == 1:
				stack.append(y)
for i in range(1, n + 1):
	if num[i] != n:
		dp[i].append(n - num[i])
ans = 0
mod = 10 ** 9 + 7

def inv(x):
	return pow(x, mod - 2, mod)
inv2 = inv(2)
inv2n = inv(pow(2, n, mod))
for i in range(1, n + 1):
	if len(dp[i]) > 1:
		ans += 1
		ans -= inv2
		ans += inv2n * (len(dp[i]) - 1)
		for val in dp[i]:
			ans -= pow(2, val, mod) * inv2n
			ans %= mod
print(ans)


import os
import sys
from collections import defaultdict
if os.getenv('LOCAL'):
	sys.stdin = open('_in.txt', 'r')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
IINF = 10 ** 18
MOD = 10 ** 9 + 7

def div_mod(a, b, mod):
	return a * pow(b, mod - 2, mod) % mod
N = int(sys.stdin.buffer.readline())
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N - 1)]
graph = [[] for _ in range(N)]
for (a, b) in AB:
	a -= 1
	b -= 1
	graph[a].append(b)
	graph[b].append(a)
children_counts = [defaultdict(int) for _ in range(N)]
hist = []
root = 0
stack = [(root, None)]
while stack:
	(v, parent) = stack.pop()
	hist.append((v, parent))
	for u in graph[v]:
		if u == parent:
			continue
		stack.append((u, v))
hist.reverse()
dfs = [0] * N
for (v, parent) in hist:
	ret = 0
	for u in graph[v]:
		if u == parent:
			continue
		cnt = dfs[u]
		children_counts[v][cnt] += 1
		ret += cnt
	ret += 1
	if v != root:
		children_counts[v][N - ret] += 1
	dfs[v] = ret
pow2 = [1]
p = 1
for _ in range(N):
	p = p * 2 % MOD
	pow2.append(p)
E = [0] * N
for (v, counts) in enumerate(children_counts):
	if len(graph[v]) == 1:
		E[v] = pow2[N]
		continue
	e = pow2[N - 1]
	for (children, cnt) in counts.items():
		curo = pow2[children] - 1
		e += curo * cnt % MOD
	E[v] = (e + 1) % MOD
E = [(pow2[N] - e) % MOD for e in E]
ans = div_mod(sum(E), pow2[N], MOD)
print(ans)


import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 9)
from functools import lru_cache

def RD():
	return sys.stdin.read()

def II():
	return int(input())

def MI():
	return map(int, input().split())

def MF():
	return map(float, input().split())

def LI():
	return list(map(int, input().split()))

def LF():
	return list(map(float, input().split()))

def TI():
	return tuple(map(int, input().split()))

def main():
	mod = 10 ** 9 + 7
	n = II()
	G = [[] for _ in range(n + 1)]
	p = [0] * (n + 1)
	v = [0] * (n + 1)
	for _ in range(n - 1):
		(a, b) = MI()
		G[a].append(b)
		G[b].append(a)
	inv2 = [1] * (n + 1)
	t = pow(pow(2, n, mod), mod - 2, mod)
	for i in range(n, -1, -1):
		inv2[i] = t
		t *= 2
		t %= mod

	def dfs(a):
		cnt = 1
		for i in G[a]:
			if p[a] == i:
				continue
			else:
				p[i] = a
				cnt += dfs(i)
		v[a] = cnt
		return cnt
	dfs(1)

	def f(a):
		return (1 - inv2[a]) * (1 - inv2[n - a]) % mod
	ans = 1 - inv2[n] - n * inv2[1]
	for i in range(1, n + 1):
		ans += f(v[i]) % mod
	print(ans % mod)
main()


N = int(input())
E = [[] for _ in range(N)]
for _ in range(N - 1):
	(A, B) = map(int, input().split())
	E[A - 1].append(B - 1)
	E[B - 1].append(A - 1)
MOD = 10 ** 9 + 7
dp = [1] * N
root = 0
parent = [0] * N
order = []

def dfs():
	parent[root] = root
	stack = [root]
	while stack:
		node = stack.pop()
		order.append(node)
		for ss in E[node]:
			if parent[node] != ss:
				stack.append(ss)
				parent[ss] = node
pow2 = [1] * (N + 1)
for i in range(1, len(pow2)):
	pow2[i] = pow2[i - 1] * 2 % MOD

def solve():
	ans = 0
	inv2 = pow(2, MOD - 2, MOD)
	p0 = pow(pow2[N - 1], MOD - 2, MOD)
	for i in reversed(order):
		if root != i:
			dp[parent[i]] += dp[i]
		p = 0
		if len(E[i]) >= 2:
			p1 = 1
			for s in E[i]:
				size = 0
				if parent[i] != s:
					size = dp[s]
				elif i != root:
					size = N - dp[i]
				else:
					continue
				p1 += pow2[size] - 1
			p = 1 - p0 * p1
			p %= MOD
		ans += p
		ans %= MOD
	ans = ans * inv2 % MOD
	print(ans)
dfs()
solve()


from sys import stdin, setrecursionlimit
from collections import deque
setrecursionlimit(10 ** 9)
INF = 1 << 60

def input():
	return stdin.readline().strip()
MOD = 1000000007
N = int(stdin.buffer.readline())
m = map(int, stdin.buffer.read().split())
AB = zip(m, m)
G = [[] for _ in range(N)]
for (a, b) in AB:
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
pow2 = [1] * (N + 1)
for i in range(N):
	pow2[i + 1] = pow2[i] * 2 % MOD
order = []
parent = [-1] * N
stack = deque([0])
while stack:
	v = stack.pop()
	order.append(v)
	for nv in G[v]:
		if parent[v] != nv:
			parent[nv] = v
			stack.append(nv)
numer = 0
nums = [0] * N
for v in reversed(order):
	tmp = 1
	for nv in G[v]:
		if parent[v] != nv:
			nums[v] += nums[nv] + 1
			tmp += pow2[nums[nv] + 1] - 1
	tmp += pow2[N - nums[v] - 1] - 1
	numer = (numer + pow2[N - 1] - tmp) % MOD
denom = pow2[N]
ans = numer * pow(denom, MOD - 2, MOD) % MOD
print(ans)


import sys
input = sys.stdin.readline
mod = 10 ** 9 + 7

def dfs(graph, N):
	ans = 0
	Par = [-1] * N
	Childs = [[] for _ in range(N)]
	stack = [0]
	while stack:
		p = stack.pop()
		if p >= 0:
			stack.append(~p)
			for np in graph[p]:
				if np != 0 and Par[np] == -1:
					stack.append(np)
					Par[np] = p
		else:
			p = ~p
			score = pow(2, N - 1, mod) - 1
			upper = N - 1
			for a in Childs[p]:
				upper -= a
				score = (score - pow(2, a, mod) + 1) % mod
			if p != 0:
				score = (score - pow(2, upper, mod) + 1) % mod
			ans = (ans + score) % mod
			Childs[Par[p]].append(N - 1 - upper + 1)
	return ans * pow(2, N * (mod - 2), mod) % mod

def main():
	N = int(input())
	graph = [[] for _ in range(N)]
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		graph[a - 1].append(b - 1)
		graph[b - 1].append(a - 1)
	print(dfs(graph, N))

def __starting_point():
	main()
__starting_point()


import sys
readline = sys.stdin.readline
N = int(readline())
graph = [[] for _ in range(N + 1)]
for i in range(N - 1):
	(a, b) = map(int, readline().split())
	graph[a].append(b)
	graph[b].append(a)
parent = [0] * (N + 1)
order = []
stack = [1]
while stack:
	x = stack.pop()
	order.append(x)
	for y in graph[x]:
		if y == parent[x]:
			continue
		parent[y] = x
		stack.append(y)
MOD = 10 ** 9 + 7
half = pow(2, MOD - 2, MOD)
power_inv = [1] * (N + 1)
size = [1] * (N + 1)
for (i, v) in enumerate(order[::-1], 1):
	p = parent[v]
	x = size[v]
	size[p] += x
	power_inv[i] = power_inv[i - 1] * half % MOD
ans = sum(((1 - power_inv[i] - power_inv[N - i] + power_inv[N]) % MOD for i in size[2:]))
ans -= N * power_inv[1] + power_inv[N] - 1
ans %= MOD
print(ans)


import sys
sys.setrecursionlimit(1000000)
readline = sys.stdin.readline
N = int(readline())
adj = [[] for i in range(N)]
for i in range(N - 1):
	(A, B) = map(int, readline().split())
	A -= 1
	B -= 1
	adj[A].append(B)
	adj[B].append(A)
mod = 10 ** 9 + 7
pow2 = [1] * (N + 1)
for (i, j) in zip(range(N), range(1, N + 1)):
	pow2[j] = pow2[i] * 2 % mod
ans = 0

def dfs(node, parent):
	global ans
	cnt = 1
	for child in adj[node]:
		if child != parent:
			cnt += dfs(child, node)
	ans += (pow2[cnt] - 1) * (pow2[N - cnt] - 1)
	ans %= mod
	return cnt
dfs(0, None)
ans = (ans - N * pow2[N - 1] + pow2[N] - 1) % mod
ans = ans * pow(pow2[N], mod - 2, mod) % mod
print(ans)


import sys
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
N = int(input())
tree = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(A, B) = map(int, input().split())
	tree[A].append(B)
	tree[B].append(A)

def dfs(u, par):
	visited[u] = True
	ret = 1
	for v in tree[u]:
		if not visited[v]:
			ret += dfs(v, u)
	if par > 0:
		tree_dic[u, par] = ret
	return ret
visited = [False] * (N + 1)
tree_dic = {}
dfs(1, 0)
bumbo = pow(2, N, MOD)
bunshi = (pow(2, N, MOD) - 1 - N * pow(2, N - 1, MOD)) % MOD
for x in tree_dic.values():
	term = (pow(2, x, MOD) - 1) * (pow(2, N - x, MOD) - 1)
	bunshi += term
	bunshi %= MOD
answer = bunshi * pow(bumbo, MOD - 2, MOD)
answer %= MOD
print(answer)


import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)
mod = 10 ** 9 + 7
(N, *AB) = map(int, open(0).read().split())
E = [[] for _ in range(N)]
for (i, (a, b)) in enumerate(zip(*[iter(AB)] * 2)):
	E[a - 1].append((b - 1, i))
	E[b - 1].append((a - 1, i))
X = [0] * N

def dfs(u, p):
	res = 1
	for (v, c) in E[u]:
		if p != c:
			res += dfs(v, c)
	X[p] = res
	return res
dfs(0, -1)
I = [1]
inv = pow(2, mod - 2, mod)
for i in range(N):
	I.append(I[-1] * inv % mod)
ans = -inv * N - I[N] + 1 + sum(((1 - I[x]) * (1 - I[N - x]) for x in X))
ans %= mod
print(ans)


def main():
	from sys import stdin
	input = stdin.readline
	mod = 10 ** 9 + 7
	n = int(input())
	ab = [list(map(int, input().split())) for _ in [0] * (n - 1)]
	pow2 = [1]
	for i in range(200000):
		pow2.append(pow2[-1] * 2 % mod)
	g = [[] for _ in [0] * n]
	[g[a - 1].append(b - 1) for (a, b) in ab]
	[g[b - 1].append(a - 1) for (a, b) in ab]
	root = 0
	d = [-1] * n
	d[root] = 0
	q = [root]
	cnt = 0
	while q:
		cnt += 1
		qq = []
		while q:
			i = q.pop()
			for j in g[i]:
				if d[j] == -1:
					d[j] = cnt
					qq.append(j)
		q = qq
	for i in range(n):
		di = d[i]
		g[i] = [j for j in g[i] if di <= d[j]]
	d = [j for (i, j) in sorted([(j, i) for (i, j) in enumerate(d)])]
	dp = [(0, 0, 1) for _ in [0] * n]
	for i in d[::-1]:
		if g:
			n = sum([dp[j][2] for j in g[i]]) + 1
			(x, y) = (pow(2, n - 1, mod) - 1, 0)
			for j in g[i]:
				(xj, yj, nj) = dp[j]
				(p1, p2) = (pow2[n - nj], pow2[nj])
				x += xj * p1 + yj * (p1 - 1) - p2 + 1
				y += yj + p2 - 1
			dp[i] = (x % mod, y % mod, n)
	x = dp[0][0]
	y = pow(2, dp[0][2], mod)
	print(x * pow(y, mod - 2, mod) % mod)
main()


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

def dfs(v):
	visited[v] = True
	for i in range(len(AL[v][CHILDREN])):
		u = AL[v][CHILDREN][i]
		if visited[u]:
			AL[v][CHILDREN][i] = None
			continue
		AL[v][SIZE] += dfs(u)
	return AL[v][SIZE]

def anaaki(v):
	ret = powp - 1
	for ch in AL[v][CHILDREN]:
		if ch is None:
			continue
		ret -= pow(2, AL[ch][SIZE], p) - 1
		ret %= p
	ret -= pow(2, n - AL[v][SIZE], p) - 1
	ret %= p
	return ret
n = int(input())
SIZE = 0
CHILDREN = 1
AL = [[1, []] for _ in range(n)]
visited = [False] * n
p = 10 ** 9 + 7
powp = pow(2, n - 1, p)
for i in range(n - 1):
	(a, b) = [int(x) - 1 for x in input().split()]
	AL[a][CHILDREN].append(b)
	AL[b][CHILDREN].append(a)
dfs(0)
numer = 0
for i in range(n):
	numer += anaaki(i)
	numer %= p
denom = powp * 2 % p
print(numer * pow(denom, p - 2, p) % p)


import sys
import math
import heapq
sys.setrecursionlimit(10 ** 7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007

def POW(x, y):
	return pow(x, y, DVSR)

def INV(x, m=DVSR):
	return pow(x, m - 2, m)

def DIV(x, y, m=DVSR):
	return x * INV(y, m) % m

def LI():
	return [int(x) for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LS():
	return input().split()

def II():
	return int(input())

def FLIST(n):
	res = [1]
	for i in range(1, n + 1):
		res.append(res[i - 1] * i % DVSR)
	return res

def gcd(x, y):
	if x < y:
		(x, y) = (y, x)
	div = x % y
	while div != 0:
		(x, y) = (y, div)
		div = x % y
	return y
N = II()
AB = [LI() for _ in range(N - 1)]
graph = [[] for _ in range(N + 1)]
for (a, b) in AB:
	graph[a].append(b)
	graph[b].append(a)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
	x = stack.pop()
	order.append(x)
	for y in graph[x]:
		if y == parent[x]:
			continue
		parent[y] = x
		stack.append(y)
x = (DVSR + 1) // 2
PWR = [1] * (N + 1)
RWP = [1] * (N + 1)
for i in range(1, N + 1):
	PWR[i] = PWR[i - 1] * 2 % DVSR
	RWP[i] = RWP[i - 1] * x % DVSR
answer = 0
size = [1] * (N + 1)
for v in order[::-1]:
	p = parent[v]
	size[p] += size[v]
	A = [size[w] for w in graph[v] if w != p]
	if v != root:
		A.append(N - 1 - sum(A))
	if len(A) == 1:
		continue
	prod = 1
	coef = 1
	for x in A:
		prod *= RWP[x]
		prod %= DVSR
		coef += PWR[x] - 1
	E = 1 - prod * coef % DVSR
	answer += E
answer *= RWP[1]
answer %= DVSR
print(answer)


import sys
sys.setrecursionlimit(10 ** 8)
MOD = 10 ** 9 + 7
N = int(input())
g_l = [[] for i in range(N)]
check_l = [-1] * N
num_l = [0] * N
for i in range(N - 1):
	(ai, bi) = list(map(int, input().split()))
	g_l[ai - 1].append(bi - 1)
	g_l[bi - 1].append(ai - 1)

def dfs(n):
	d = 1
	if check_l[n] > 0:
		return num_l[n]
	check_l[n] = 1
	for next_n in g_l[n]:
		d += dfs(next_n)
	num_l[n] = d
	return d

def modinv(a):
	return pow(a, MOD - 2, MOD)

def solve():
	dfs(0)
	pow_l = [None] * (N + 1)
	pow_l[0] = 1
	for i in range(1, N + 1):
		pow_l[i] = pow_l[i - 1] * 2 % MOD
	ans = 0
	for i in range(1, N):
		ans = (ans + (pow_l[num_l[i]] - 1) * (pow_l[N - num_l[i]] - 1) % MOD) % MOD
	ans = (ans + (pow_l[N] - 1) - N * pow_l[N - 1] % MOD) % MOD
	y = ans
	x = pow(2, N, MOD)
	z = y * modinv(x) % MOD
	print(z)
solve()


import sys
from collections import deque
read = sys.stdin.buffer.read

def main():
	MOD = 1000000007
	(N, *AB) = map(int, read().split())
	G = [[] for _ in range(N)]
	for (a, b) in zip(AB[::2], AB[1::2]):
		G[a - 1].append(b - 1)
		G[b - 1].append(a - 1)
	stack = deque([0])
	order = []
	prev = [0] * N
	prev[0] = -1
	while stack:
		v = stack.pop()
		order.append(v)
		for nv in G[v]:
			if nv != prev[v]:
				stack.append(nv)
				prev[nv] = v
	pow2 = [0] * (N + 1)
	pow2[0] = 1
	for i in range(N):
		pow2[i + 1] = pow2[i] * 2 % MOD
	nodes = [1] * N
	numer = 0
	for v in reversed(order):
		if prev[v] != -1:
			nodes[prev[v]] += nodes[v]
		numer = (numer + pow2[N - 1] - 1 - (pow2[N - nodes[v]] - 1)) % MOD
		for nv in G[v]:
			if nv != prev[v]:
				numer = (numer - (pow2[nodes[nv]] - 1)) % MOD
	denom = pow2[N]
	ans = numer * pow(denom, MOD - 2, MOD) % MOD
	print(ans)
	return
main()


n = int(input())
peer = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	peer[a].append(b)
	peer[b].append(a)
pre = [10 ** 6 for _ in range(n)]
pre[0] = -1
pst = [[] for _ in range(n)]
rank = [[0]]
seen = [0 for _ in range(n)]
seen[0] = 1
now = [0]
while now:
	last = now
	now = []
	for x in last:
		for y in peer[x]:
			if seen[y] == 0:
				seen[y] = 1
				now.append(y)
				pre[y] = x
				pst[x].append(y)
	rank.append(now)
rank = rank[1:-1]
family = [1 for _ in range(n)]
rank.reverse()
for z in rank:
	for w in z:
		family[pre[w]] += family[w]
mod = 10 ** 9 + 7
half = 5 * 10 ** 8 + 4
satoshi = 1
btc = [1]
for _ in range(n):
	satoshi *= half
	satoshi %= mod
	btc.append(btc[-1] * 2 % mod)
ans = 0
for i in range(n):
	if i == 0:
		if len(pst[i]) == 1:
			pass
		else:
			q = []
			for x in pst[i]:
				q.append(family[x])
			tmp = -len(q) + 1
			for p in q:
				tmp += btc[p]
			tmp = btc[n - 1] - tmp
			ans += tmp
	elif len(pst[i]) == 0:
		pass
	else:
		q = []
		for x in pst[i]:
			q.append(family[x])
		q.append(n - 1 - sum(q))
		tmp = -len(q) + 1
		for p in q:
			tmp += btc[p]
		tmp = btc[n - 1] - tmp
		ans += tmp
ans *= satoshi
ans %= mod
print(ans)


import sys
sys.setrecursionlimit(10 ** 9)
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
mod = 10 ** 9 + 7
n = int(input())
G = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	G[a].append(b)
	G[b].append(a)
cnt = [0] * n

def dfs(cur, prev):
	tmp = 1
	for to in G[cur]:
		if to != prev:
			tmp += dfs(to, cur)
	cnt[cur] = tmp
	return tmp
dfs(0, -1)
power = [0] * n
powe2_n = pow(2, n, mod)
powe2_n = pow(powe2_n, mod - 2, mod)
power[n - 1] = powe2_n
for i in reversed(range(n - 1)):
	powe2_n *= 2
	powe2_n %= mod
	power[i] = powe2_n
ans = 0
from collections import deque
que = deque()
que.append((0, -1))
while que:
	(cur, prev) = que.pop()
	if len(G[cur]) == 1:
		if prev == -1:
			que.append((G[cur][0], cur))
		continue
	prob = 1
	prob -= power[n - 2]
	for to in G[cur]:
		if to == prev:
			bubun_cnt = n - cnt[cur]
		else:
			que.append((to, cur))
			bubun_cnt = cnt[to]
		tmp = 1 - power[bubun_cnt - 1]
		tmp *= power[n - 1 - bubun_cnt - 1]
		prob -= tmp
	prob %= mod
	ans += power[0] * prob
	ans %= mod
print(ans)


from collections import deque
n = int(input())
e = [[] for _ in range(n)]
for i in range(n - 1):
	(ai, bi) = map(int, input().split())
	ai -= 1
	bi -= 1
	e[ai].append(bi)
	e[bi].append(ai)
deg = [len(e[i]) for i in range(n)]
dep0 = [-1] * n
dep0[0] = 0
Q = deque()
Q.append(0)
while Q:
	v = Q.popleft()
	for u in e[v]:
		if dep0[u] < 0:
			dep0[u] = dep0[v] + 1
			Q.append(u)
size = [1] * n
for i in range(n):
	flag = True
	for j in e[i]:
		if dep0[i] < dep0[j]:
			flag = False
			break
	if flag:
		Q.append(i)
while Q:
	v = Q.popleft()
	for u in e[v]:
		if dep0[u] < dep0[v]:
			size[u] += size[v]
			deg[u] -= 1
			if deg[u] == 1 and u:
				Q.append(u)
ans = 0
mod = 10 ** 9 + 7
x = pow(2, mod - 2, mod)
pw_rev = [1] * (n + 1)
for i in range(1, n + 1):
	pw_rev[i] = pw_rev[i - 1] * x % mod
for u in range(n):
	for v in e[u]:
		if dep0[u] < dep0[v]:
			ans += (1 - pw_rev[size[v]]) * (1 - pw_rev[n - size[v]])
	ans %= mod
print((ans - n * x + 1 - pw_rev[n]) % mod)


import sys
input = lambda : sys.stdin.readline().rstrip()
mod = 10 ** 9 + 7
n = int(input())
edge = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = list(map(int, input().split()))
	edge[a - 1].append(b - 1)
	edge[b - 1].append(a - 1)
inf = 10 ** 6
Par = [inf] * n
Par[0] = -1
Deg = [0] * n
Deg[0] = 0
Chk = [0]
while Chk:
	c = Chk.pop()
	for next in edge[c]:
		if Par[next] == inf:
			Par[next] = c
			Deg[next] += 1
			Chk.append(next)
from collections import deque
TS = list((v for v in range(n) if Deg[v] == 0))
D = deque(TS)
while D:
	v = D.popleft()
	for t in edge[v]:
		if t != Par[v]:
			Deg[t] -= 1
			if Deg[t] == 0:
				D.append(t)
				TS.append(t)
Used = [False] * n
C = [0] * n
for i in reversed(list(range(n))):
	v = TS[i]
	Used[v] = True
	for g in edge[v]:
		if not Used[g]:
			C[g] += C[v] + 1
H = [0] * n
H[0] = 1
H[1] = pow(2, mod - 2, mod)
for i in range(2, n):
	H[i] = H[i - 1] * H[1] % mod
ans = 0
for i in range(n):
	if len(edge[i]) == 1:
		continue
	else:
		A = []
		for e in edge[i]:
			if e == Par[i]:
				A.append(n - 1 - C[i])
			else:
				A.append(C[e] + 1)
		cur = 1 + (len(edge[i]) - 1) * H[-1]
		for a in A:
			cur -= H[n - 1 - a]
		ans = (ans + cur) % mod
print(ans * H[1] % mod)


def main():
	import sys
	input = lambda : sys.stdin.readline().rstrip()
	sys.setrecursionlimit(max(1000, 10 ** 9))
	write = lambda x: sys.stdout.write(x + '\n')
	from collections import defaultdict
	n = int(input())
	ns = defaultdict(set)
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		u -= 1
		v -= 1
		ns[u].add(v)
		ns[v].add(u)

	def dfs(start):
		q = [start]
		seen = [None] * n
		done = [None] * n
		parent = [None] * n
		parent[start] = -1
		d0 = 0
		d1 = n
		while q:
			u = q.pop()
			if u >= 0:
				if seen[u] is not None:
					continue
				seen[u] = d0
				d0 += 1
				q.append(~u)
				for v in ns[u]:
					if seen[v] is None:
						q.append(v)
						parent[v] = u
			else:
				d1 -= 1
				done[~u] = d1
		return (seen, done, parent)
	(seen, done, parent) = dfs(0)
	done = [(u, d) for (u, d) in enumerate(done)]
	done.sort(key=lambda x: -x[1])
	bs = {}
	for (u, _) in done:
		val = 1
		p = parent[u]
		for v in ns[u]:
			if v != p:
				val += bs[u, v]
		bs[p, u] = val
	bs[0, -1] = 0
	for (u, _) in reversed(done):
		p = parent[u]
		for v in ns[u]:
			if v == p:
				continue
			b1 = bs[p, u]
			b2 = bs[u, v]
			b3 = bs[u, p]
			bb = b1 - b2 + b3
			bs[v, u] = bb
	M = 10 ** 9 + 7
	p1 = pow(2, n - 1, M)
	p2 = pow(2, n, M)
	p3 = pow(p2, M - 2, M)
	ans = 0
	for u in range(n):
		s = 0
		for v in ns[u]:
			s += pow(2, bs[u, v], M) - 1
			s %= M
		val = p1 - s - 1
		ans += val
		ans %= M
	ans *= p3
	ans %= M
	print(ans % M)
main()


import sys
sys.setrecursionlimit(10 ** 6)
LI = lambda : list(map(int, input().split()))
N = int(input())
AB = [LI() for _ in range(N - 1)]
link = [[] for _ in range(N)]
children = [[] for _ in range(N)]
w = [1] * N
visit = [False] * N
MOD = 10 ** 9 + 7

def create_link():
	for (a, b) in AB:
		link[a - 1].append(b - 1)
		link[b - 1].append(a - 1)

def dfs(s):
	visit[s] = True
	for t in link[s]:
		if visit[t]:
			continue
		children[s].append(t)
		dfs(t)
		w[s] += w[t]

def modinv(x):
	return pow(x, MOD - 2, MOD)

def main():
	create_link()
	dfs(0)
	p2 = [None] * (N + 1)
	p2[0] = 1
	for i in range(N):
		p2[i + 1] = 2 * p2[i] % MOD
	x = 0
	for i in range(N):
		s = p2[N - w[i]]
		for j in children[i]:
			s = (s + p2[w[j]] - 1) % MOD
		x = (x + p2[N - 1] - s) % MOD
	y = p2[N]
	ans = x * modinv(y) % MOD
	print(ans)

def __starting_point():
	main()
__starting_point()


def JOI14_B():
	N = I()
	A = [I() for _ in range(N)]
	A.extend(A)
	dp = [[0] * (N * 2 + 1) for _ in range(N * 2 + 1)]
	for j in range(N):
		for i in range(N * 2 - j):
			if (N - j) % 2 == 1:
				dp[i][i + j] = max(dp[i + 1][i + j] + A[i], dp[i][i + j - 1] + A[i + j])
			elif A[i] > A[i + j]:
				dp[i][i + j] = dp[i + 1][i + j]
			else:
				dp[i][i + j] = dp[i][i + j - 1]
	ans = 0
	for i in range(N):
		ans = max(ans, dp[i][i + N - 1])
	print(ans)
	return

def square869120Contest1_G():

	def held_karp(dists, TL):
		n = len(dists)
		C = {}
		dp = defaultdict(int)
		for k in range(1, n):
			C[1 << k, k] = (dists[0][k], 0)
			dp[1 << k, k] = 1
		for subset_size in range(2, n):
			for subset in itertools.combinations(range(1, n), subset_size):
				bits = 0
				for bit in subset:
					bits |= 1 << bit
				shortest_length = inf
				for k in subset:
					prev = bits & ~(1 << k)
					res = []
					for m in subset:
						if not (prev, m) in C:
							continue
						if m == 0 or m == k:
							continue
						if C[prev, m][0] + dists[m][k] > TL[m][k]:
							continue
						res.append((C[prev, m][0] + dists[m][k], m))
						if shortest_length > C[prev, m][0] + dists[m][k]:
							shortest_length = C[prev, m][0] + dists[m][k]
					if not res:
						continue
					C[bits, k] = min(res)
					for (d, m) in res:
						if shortest_length != d:
							continue
						dp[bits, k] += dp[prev, m]
		bits = 2 ** n - 1 - 1
		res = []
		shortest_length = inf
		for k in range(1, n):
			if not (bits, k) in C:
				continue
			if C[bits, k][0] + dists[k][0] > TL[k][0]:
				continue
			res.append((C[bits, k][0] + dists[k][0], k))
			if shortest_length > C[bits, k][0] + dists[k][0]:
				shortest_length = C[bits, k][0] + dists[k][0]
		if not res:
			return False
		(opt, parent) = min(res)
		way = 0
		for (d, k) in res:
			if not (bits, k) in C:
				continue
			if C[bits, k][0] + dists[k][0] > TL[k][0]:
				continue
			if shortest_length < d:
				continue
			way += dp[bits, k]
		path = []
		for i in range(n - 1):
			path.append(parent)
			new_bits = bits & ~(1 << parent)
			(_, parent) = C[bits, parent]
			bits = new_bits
		path.append(0)
		return (shortest_length, list(reversed(path)), way)
	(N, M) = LI()
	dist = [[inf] * N for _ in range(N)]
	TL = [[0] * N for _ in range(N)]
	for _ in range(M):
		(s, t, d, time) = LI()
		s -= 1
		t -= 1
		dist[s][t] = dist[t][s] = d
		TL[s][t] = TL[t][s] = time
	ans = held_karp(dist, TL)
	if not ans or ans[2] == 0:
		print('IMPOSSIBLE')
		return
	print(ans[0], ans[2])
	return

def JOI13_D():

	def solve(yday, leader, next):
		a = [0] * 3
		for i in range(3):
			if next & 1 << i == 1 << i:
				a[i] = 1
		rep = 0
		if a[leader] == 0:
			return rep
		for i in range(3):
			if yday & 1 << i == 1 << i:
				if a[i] == 1:
					rep = 1
		return rep
	N = I()
	S = SI()
	member = {'J': 0, 'O': 1, 'I': 2}
	dp = [[0] * 8 for _ in range(N + 1)]
	dp[0][1] = 1
	for i in range(N):
		leader = member[S[i]]
		for j in range(8):
			for k in range(8):
				dp[i + 1][j] += dp[i][k] * solve(k, leader, j)
	ans = sum(dp[-1]) % 10007
	print(ans)
	return

def JOI16_D():
	(N, M) = LI()
	A = [I() - 1 for _ in range(N)]
	imos = [[0] * (N + 1) for _ in range(M)]
	for i in range(M):
		for j in range(N):
			imos[i][j + 1] += imos[i][j] + (A[j] != i)
	loop = 2 ** M
	dp = [inf] * loop
	dp[0] = 0
	cnt = Counter(A)
	L = [0] * loop
	for i in range(loop):
		for j in range(M):
			if i & 1 << j == 1 << j:
				continue
			next = i | 1 << j
			if L[next] == 0:
				L[next] = L[i] + cnt[j]
			cur = imos[j][L[next]] - imos[j][L[i]]
			if dp[next] > dp[i] + cur:
				dp[next] = dp[i] + cur
	ans = dp[-1]
	print(ans)
	return

def ABC6_D():
	N = I()
	C = [I() for _ in range(N)]
	LIS = [C[0]]
	for i in range(N):
		if C[i] > LIS[-1]:
			LIS.append(C[i])
		else:
			LIS[bisect.bisect_left(LIS, C[i])] = C[i]
	print(N - len(LIS))
	return

def ABC134_E():
	N = I()
	A = [I() for _ in range(N)]
	que = deque()
	que.append(A[0])
	L = 1
	for i in range(1, N):
		cur = bisect.bisect_left(que, A[i])
		if cur == 0:
			que.appendleft(A[i])
			L += 1
		else:
			que[cur - 1] = A[i]
	ans = len(que)
	print(ans)
	return

def JOI7_F():

	def dijkstra_2(edge_adj, node, start):
		dist = [inf] * node
		used = [False] * node
		dist[start] = 0
		while True:
			v = -1
			for i in range(node):
				if not used[i] and (v == -1 or dist[v] > dist[i]):
					v = i
			if v == -1:
				break
			used[v] = True
			for i in range(node):
				if dist[i] > dist[v] + edge_adj[v][i]:
					dist[i] = dist[v] + edge_adj[v][i]
		return dist
	(N, K) = LI()
	V = [[inf] * N for _ in range(N)]
	ans = []
	for _ in range(K):
		A = LI()
		s = A[1] - 1
		t = A[2] - 1
		if A[0] == 1:
			if V[s][t] <= A[3]:
				continue
			V[s][t] = A[3]
			V[t][s] = A[3]
		else:
			dist = dijkstra_2(V, N, s)
			ans.append(dist[t])
	for v in ans:
		if v == inf:
			print(-1)
			continue
		print(v)
	return

def JOI15_E():

	def bfs(n, E, fordfs):
		W = [inf] * n
		que = deque()
		for e in E:
			e -= 1
			W[e] = 0
			que.append(e)
		while que:
			now = que.popleft()
			nowW = W[now]
			for ne in fordfs[now]:
				if W[ne] > nowW + 1:
					W[ne] = nowW + 1
					que.append(ne)
		return W

	class Dijkstra(object):

		def __init__(self, edges, start=0):
			self.__dist = [inf] * len(edges)
			self.__dist[start] = 0
			self.__calculate(edges, start)

		@property
		def dist(self):
			return self.__dist

		def __calculate(self, edges, start):
			Q = [(0, start)]
			while Q:
				(dist, v) = heapq.heappop(Q)
				if self.dist[v] < dist:
					continue
				for (u, cost) in edges[v]:
					if self.dist[u] > self.dist[v] + cost:
						self.__dist[u] = self.dist[v] + cost
						heapq.heappush(Q, (self.dist[u], u))
	(N, M, K, S) = LI()
	(P, Q) = LI()
	C = [I() for _ in range(K)]
	V = [[] for _ in range(N)]
	for _ in range(M):
		(s, t) = LI()
		s -= 1
		t -= 1
		V[s].append(t)
		V[t].append(s)
	L = bfs(N, C, V)
	cost = [[] for _ in range(N)]
	for i in range(N):
		for v in V[i]:
			if L[v] == 0:
				continue
			elif L[v] <= S:
				cost[i].append((v, Q))
			else:
				cost[i].append((v, P))
	di = Dijkstra(cost)
	ans = di.dist
	if L[-1] <= S:
		print(ans[N - 1] - Q)
	else:
		print(ans[N - 1] - P)
	return

def JOI13_E():

	def bfs(n, e, fordfs):
		W = [inf] * n
		W[e] = 0
		que = deque()
		que.append(e)
		while que:
			now = que.popleft()
			nowW = W[now]
			for ne in fordfs[now]:
				if W[ne] == inf:
					W[ne] = nowW + 1
					que.append(ne)
		return W

	def dijkstra_2(edge_adj, node, start):
		dist = [inf] * node
		used = [False] * node
		dist[start] = 0
		while True:
			v = -1
			for i in range(node):
				if not used[i] and (v == -1 or dist[v] > dist[i]):
					v = i
			if v == -1:
				break
			used[v] = True
			for i in range(node):
				if dist[i] > dist[v] + edge_adj[v][i]:
					dist[i] = dist[v] + edge_adj[v][i]
		return dist
	(N, K) = LI()
	C = [[] for _ in range(N)]
	V = [[] for _ in range(N)]
	for i in range(N):
		C[i] = LI()
	for i in range(K):
		(a, b) = LI()
		a -= 1
		b -= 1
		V[a].append(b)
		V[b].append(a)
	costV = [[inf] * N for _ in range(N)]
	for i in range(N):
		L = bfs(N, i, V)
		c = C[i][0]
		l = C[i][1]
		for j in range(N):
			if i == j:
				continue
			if L[j] <= l:
				costV[i][j] = c
	dist = dijkstra_2(costV, N, 0)
	ans = dist[N - 1]
	print(ans)
	return

def ABC12_D():

	def warshall_floyd(n, d):
		for k in range(n):
			for i in range(n):
				for j in range(n):
					d[i][j] = min(d[i][j], d[i][k] + d[k][j])
		return d
	(N, M) = LI()
	V = [[inf] * N for _ in range(N)]
	for i in range(N):
		V[i][i] = 0
	for _ in range(M):
		(a, b, t) = LI()
		a -= 1
		b -= 1
		V[a][b] = t
		V[b][a] = t
	L = warshall_floyd(N, V)
	ans = inf
	for i in range(N):
		cur = max(L[i])
		ans = min(ans, cur)
	print(ans)
	return

def ABC79_D():

	def warshall_floyd(n, d):
		for k in range(n):
			for i in range(n):
				for j in range(n):
					d[i][j] = min(d[i][j], d[i][k] + d[k][j])
		return d
	(H, W) = LI()
	C = [LI() for _ in range(10)]
	A = [LI() for _ in range(H)]
	L = warshall_floyd(10, C)
	ans = 0
	for a in A:
		for i in a:
			if i >= 0:
				ans += L[i][1]
	print(ans)
	return

def JOIgassyuku10_3():
	(N, M, K) = LI()
	V = [[] for _ in range(N)]
	for _ in range(M):
		(a, b, c) = LI()
		a -= 1
		b -= 1
		V[a].append((b, c))
		V[b].append((a, c))
	return

def ABC74_D():

	def warshall_floyd(n, d):
		for k in range(n):
			for i in range(n):
				for j in range(n):
					d[i][j] = min(d[i][j], d[i][k] + d[k][j])
		return d
	N = I()
	A = [LI() for _ in range(N)]
	dist = warshall_floyd(N, copy.deepcopy(A))
	shortest_path = 0
	for i in range(N):
		for j in range(N):
			if i == j:
				continue
			if dist[i][j] < A[i][j]:
				print(-1)
				return
			if dist[i][j] > A[i][j]:
				continue
			flag = True
			for k in range(N):
				if i == k or j == k:
					continue
				judge = dist[i][k] + dist[k][j] - dist[i][j]
				if judge == 0:
					flag = False
			if flag:
				shortest_path += A[i][j]
	ans = shortest_path // 2
	print(ans)
	return

def ABC65_D():

	class Kruskal_UnionFind:

		def __init__(self, N):
			self.edges = []
			self.rank = [0] * N
			self.par = [i for i in range(N)]
			self.counter = [1] * N

		def add(self, u, v, d):
			self.edges.append([u, v, d])

		def find(self, x):
			if self.par[x] == x:
				return x
			else:
				self.par[x] = self.find(self.par[x])
				return self.par[x]

		def unite(self, x, y):
			x = self.find(x)
			y = self.find(y)
			if x != y:
				z = self.counter[x] + self.counter[y]
				(self.counter[x], self.counter[y]) = (z, z)
			if self.rank[x] < self.rank[y]:
				self.par[x] = y
			else:
				self.par[y] = x
				if self.rank[x] == self.rank[y]:
					self.rank[x] += 1

		def size(self, x):
			x = self.find(x)
			return self.counter[x]

		def same(self, x, y):
			return self.find(x) == self.find(y)

		def Kruskal(self):
			edges = sorted(self.edges, key=lambda x: x[2])
			res = 0
			for e in edges:
				if not self.same(e[0], e[1]):
					self.unite(e[0], e[1])
					res += e[2]
			return res
	N = I()
	X = []
	for i in range(N):
		(a, b) = LI()
		X.append((a, b))
	P = defaultdict(set)
	for (i, x) in enumerate(X):
		P[x] = i
	graph = Kruskal_UnionFind(N + 1)
	X.sort(key=lambda x: x[0])
	for i in range(N - 1):
		if X[i + 1][0] - X[i][0] > abs(X[i + 1][1] - X[i][1]):
			continue
		r = X[i + 1][0] - X[i][0]
		graph.add(P[X[i]], P[X[i + 1]], r)
	X.sort(key=lambda x: x[1])
	for i in range(N - 1):
		if X[i + 1][1] - X[i][1] > abs(X[i + 1][0] - X[i][0]):
			continue
		r = X[i + 1][1] - X[i][1]
		graph.add(P[X[i]], P[X[i + 1]], r)
	ans = graph.Kruskal()
	print(ans)
	return

def ABC84_D():

	def is_prime(n):
		if n == 1:
			return False
		for k in range(2, int(math.sqrt(n)) + 1):
			if n % k == 0:
				return False
		return True

	def like_2017(x):
		if is_prime(x) and is_prime(x // 2 + 1):
			return True
		return False
	Q = I()
	maxX = 10 ** 5
	imos = [0] * (maxX + 1)
	for i in range(maxX + 1):
		if like_2017(i) and i != 2:
			imos[i] = imos[i - 1] + 1
		else:
			imos[i] = imos[i - 1]
	L = [LI() for _ in range(Q)]
	ans = []
	for (l, r) in L:
		cur = imos[r] - imos[l - 1]
		ans.append(cur)
	for v in ans:
		print(v)
	return

def ABC34_C():

	def cmb(n, r, mod):
		cur = 1
		for i in range(r):
			cur *= n - i
			cur %= mod
		for i in range(r):
			cur *= pow(i + 1, mod - 2, mod)
			cur %= mod
		return cur
	(W, H) = LI()
	r = W + H - 2
	l = H - 1
	ans = cmb(r, l, mod)
	print(ans)
	return

def ABC145_D():

	def cmb(n, r, mod):
		cur = 1
		for i in range(r):
			cur *= n - i
			cur %= mod
		for i in range(r):
			cur *= pow(i + 1, mod - 2, mod)
			cur %= mod
		return cur
	(X, Y) = LI()
	if (X + Y) % 3 != 0:
		print(0)
		return
	r = (X + Y) // 3
	l = X - (X + Y) // 3
	if l < 0:
		print(0)
		return
	ans = cmb(r, l, mod)
	print(ans)
	return

def ABC21_D():

	def cmb(n, r, mod):
		cur = 1
		for i in range(r):
			cur *= n - i
			cur %= mod
		for i in range(r):
			cur *= pow(i + 1, mod - 2, mod)
			cur %= mod
		return cur
	N = I()
	K = I()
	r = N + K - 1
	l = K
	ans = cmb(r, l, mod)
	print(ans)
	return

def ABC149_F():

	def dfs(n, s, edges, children):
		cur = 1
		children[s] = 0
		for i in edges[s]:
			if children[i] != -1:
				continue
			children[i] = True
			(now, children) = dfs(n, i, edges, children)
			cur += now
		children[s] = cur
		return (cur, children)
	N = I()
	V = [[] for _ in range(N)]
	for _ in range(N - 1):
		(a, b) = LI()
		a -= 1
		b -= 1
		V[a].append(b)
		V[b].append(a)
	children = [-1] * N
	C = dfs(N, 0, V, children)[1]
	inv = pow(2, mod - 2, mod)
	ans = (1 - pow(inv, N, mod) - N * inv) % mod
	p = [pow(inv, i, mod) for i in range(N)]
	for i in range(1, N):
		c = C[i]
		d = N - c
		cur = (p[c] - 1) * (p[d] - 1)
		ans += cur
		ans %= mod
	print(ans)
	return

def square869120Contest1_E():
	(N, Q) = LI()
	A = LI()
	C = LI()
	C.append(1)
	L = [0] * N
	for i in range(1, N):
		L[i] = pow(A[i - 1], A[i], mod) + L[i - 1]
	ans = 0
	now = 0
	for i in range(Q + 1):
		next = C[i] - 1
		cur = abs(L[next] - L[now])
		ans += cur
		ans %= mod
		now = next
	print(ans)
	return
import sys, copy, bisect, itertools, heapq, math, random
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque
import gc

def I():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LSI():
	return list(map(str, sys.stdin.readline().split()))

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
_ep = 10 ** (-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
sys.setrecursionlimit(10 ** 6)
ABC149_F()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def main():
	MOD = 10 ** 9 + 7
	n = int(input())
	T = [[] for _ in range(n)]
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		a -= 1
		b -= 1
		T[a].append(b)
		T[b].append(a)
	C = [[] for _ in range(n)]
	seen = [False] * n
	dp = [0] * n

	def dfs(v):
		cnt = 1
		seen[v] = True
		for nv in T[v]:
			if seen[nv]:
				continue
			C[v].append(nv)
			cnt += dfs(nv)
		dp[v] = cnt
		return cnt
	dfs(0)
	p = [1] * (n + 1)
	inv = [1] * (n + 1)
	inv_two = pow(2, MOD - 2, MOD)
	for i in range(n):
		p[i + 1] = p[i] * 2 % MOD
		inv[i + 1] = inv[i] * inv_two % MOD
	ans = 0
	for i in range(n):
		s = 1
		t = 1
		cnt = 1
		for c in C[i]:
			l = dp[c]
			s *= inv[l]
			s %= MOD
			t += p[l] - 1
			t %= MOD
			cnt += l
		r = n - cnt
		s *= inv[r]
		s %= MOD
		t += p[r] - 1
		t %= MOD
		res = (1 - s * t) % MOD * inv_two
		res %= MOD
		ans += res
		ans %= MOD
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys
readline = sys.stdin.readline
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
n = ni()
G = [list() for _ in range(n)]
for _ in range(n - 1):
	(a, b) = nm()
	a -= 1
	b -= 1
	G[a].append(b)
	G[b].append(a)
mod = 10 ** 9 + 7
dub = [1] * (n + 1)
for i in range(n):
	dub[i + 1] = dub[i] * 2
	if dub[i + 1] > mod:
		dub[i + 1] -= mod
size = [-1] * n
q = [0]
while q:
	v = q[-1]
	if size[v] < 0:
		for x in G[v]:
			if size[x] < 0:
				q.append(x)
		size[v] = 0
	else:
		size[v] = 1
		for x in G[v]:
			size[v] += size[x]
		q.pop()
ans = 0
for v in range(n):
	c = 0
	res = 1
	for x in G[v]:
		if size[x] < size[v]:
			c += size[x]
			res += dub[size[x]] - 1
	res += dub[n - 1 - c] - 1
	res %= mod
	ans = (ans + dub[n - 1] - res) % mod
print(ans * pow(dub[n], mod - 2, mod) % mod)


from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10 ** 20

def LI():
	return list(map(int, sys.stdin.readline().split()))

def I():
	return int(sys.stdin.readline())

def LS():
	return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

def S():
	return sys.stdin.buffer.readline().rstrip().decode('utf-8')

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]

def SRL(n):
	return [list(S()) for i in range(n)]

def MSRL(n):
	return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n = I()
G = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = LI()
	G[a - 1] += [b - 1]
	G[b - 1] += [a - 1]
par = [-1] * n
cnt = [0] * n

def f(u):
	ret = 1
	for v in G[u]:
		if v == par[u]:
			continue
		par[v] = u
		ret += f(v)
	cnt[u] = ret
	return ret
f(0)
pow2 = [1] * (n + 1)
for i in range(1, n + 1):
	pow2[i] = pow2[i - 1] * 2 % mod
q = deque([0])
ans = 0
while q:
	u = q.pop()
	ret = pow2[n - 1] - 1
	for v in G[u]:
		if v == par[u]:
			continue
		ret -= pow2[cnt[v]] - 1
		q += [v]
	ret -= pow2[n - cnt[u]] - 1
	ans = (ans + ret) % mod
print(ans * pow(pow2[n], mod - 2, mod) % mod)


import sys
sys.setrecursionlimit(10 ** 8)
mod = 10 ** 9 + 7
N = int(input())
G = [[] for i in range(N + 1)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	G[a].append(b)
	G[b].append(a)
S = -1
for i in range(1, N + 1):
	if len(G[i]) == 1:
		S = i
		break
visited = [False for i in range(N + 1)]
parent = [-1 for i in range(N + 1)]
count = [1 for i in range(N + 1)]
ans = N * pow(2, N - 1, mod)

def dfs(node):
	visited[node] = True
	for child in G[node]:
		if visited[child] == False:
			parent[child] = node
			dfs(child)
	for child in G[node]:
		if child != parent[node]:
			count[node] += count[child]
powers = [1 for i in range(2 * 10 ** 5 + 1)]
for i in range(1, 2 * 10 ** 5 + 1):
	powers[i] = powers[i - 1] * 2 % mod
dfs(S)
ans = 0
for i in range(1, N + 1):
	if len(G[i]) > 1:
		ans += powers[N - 1]
		for x in G[i]:
			if x != parent[i]:
				ans -= powers[count[x]]
		ans -= powers[N - count[i]]
		ans += len(G[i]) - 1
		ans %= mod
D = pow(2, N, mod)
print(ans * pow(D, mod - 2, mod) % mod)


import sys
sys.setrecursionlimit(10 ** 6)
N = int(input())
adj = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	adj[a].append(b)
	adj[b].append(a)

def dfs(v, p=-1):
	nonlocal ans
	res = 1
	ts = []
	for u in adj[v]:
		if u == p:
			continue
		t = dfs(u, v)
		res += t
		ts.append(t)
	if p != -1:
		ts.append(N - res)
	now = pows[N - 1] - 1
	for t in ts:
		now -= pows[t] - 1
	ans += now
	return res
ans = 0
MOD = 10 ** 9 + 7
pows = [1] * (N + 1)
for i in range(1, N + 1):
	pows[i] = pows[i - 1] * 2 % MOD
dfs(1)
print(ans * pow(pows[N], MOD - 2, MOD) % MOD)


from collections import defaultdict, deque
mod = 10 ** 9 + 7
N = int(input())
g = [[] for _ in range(N)]
d = defaultdict(lambda : -1)
p2 = [1] * (N + 1)
p2[1] = pow(2, mod - 2, mod)
for i in range(N):
	p2[i + 1] = p2[i] * p2[1] % mod
for i in range(N - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	g[a].append(b)
	g[b].append(a)
q = deque([[a, b]])
while q:
	(i, j) = q.pop()
	s = 1
	f = True
	for k in g[j]:
		if k == i:
			continue
		if (j, k) not in d:
			if f:
				q.append([i, j])
			q.append([j, k])
			f = False
		else:
			s += d[j, k]
	if f:
		d[i, j] = s
q = deque([[b, a]])
while q:
	(i, j) = q.pop()
	s = 1
	f = True
	for k in g[j]:
		if k == i:
			continue
		if (j, k) not in d:
			if f:
				q.append([i, j])
			q.append([j, k])
			f = False
		else:
			s += d[j, k]
	if f:
		d[i, j] = s
ans = 1 - p2[N] - N * p2[1]
for i in range(N):
	for j in g[i]:
		if j < i:
			continue
		n = max(d[i, j], d[j, i])
		ans += (1 - p2[n]) * (1 - p2[N - n])
		ans %= mod
print(ans)


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
from collections import deque
con = 10 ** 9 + 7
INF = float('inf')

def getlist():
	return list(map(int, input().split()))

class Graph(object):

	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

def DFS(G, W, Wlist, visit, node):
	for i in G.graph[node]:
		if visit[i] == 0:
			visit[i] = 1
			DFS(G, W, Wlist, visit, i)
			W[node] += W[i]
			Wlist.append(W[i])

class BFS(object):

	def __init__(self, graph, s, N):
		self.g = graph.graph
		self.Q = deque()
		self.Q.append(s)
		self.dist = [INF] * N
		self.dist[s] = 0
		self.prev = [None] * N
		self.prev[s] = -1
		self.order = []
		while self.Q:
			v = self.Q.popleft()
			self.order.append(v)
			for i in self.g[v]:
				if self.dist[i] == INF:
					self.dist[i] = self.dist[v] + 1
					self.prev[i] = v
					self.Q.append(i)

def main():
	N = int(input())
	G = Graph()
	Nedge = [0] * N
	for i in range(N - 1):
		(a, b) = getlist()
		a -= 1
		b -= 1
		G.add_edge(a, b)
		G.add_edge(b, a)
		Nedge[a] += 1
		Nedge[b] += 1
	W = [1] * N
	BF = BFS(G, 0, N)
	for i in range(N - 1, 0, -1):
		v = BF.order[i]
		W[BF.prev[v]] += W[v]
	Wlist = []
	for i in range(N):
		for j in G.graph[i]:
			if j != BF.prev[i]:
				Wlist.append(W[j])
	for i in range(N):
		Wlist.append(N - W[i])
	pow2 = pow(2, N - 1, con)
	ans_up = N * (pow2 - 1)
	for i in Wlist:
		ans_up -= pow(2, i, con) - 1
		ans_up %= con
	ans = ans_up * pow(pow2 * 2, con - 2, con)
	print(ans % con)
main()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)

def solve():
	N = int(input())
	AB = [tuple(map(int, input().split())) for i in range(N - 1)]
	MOD = 10 ** 9 + 7
	es = [[] for _ in range(N)]
	for (a, b) in AB:
		(a, b) = (a - 1, b - 1)
		es[a].append(b)
		es[b].append(a)
	cs = [1] * N

	def dfs(v, p=-1):
		ret = 1
		for to in es[v]:
			if to == p:
				continue
			ret += dfs(to, v)
		cs[v] = ret
		return ret
	dfs(0)
	pow2 = [1]
	for i in range(N):
		pow2.append(pow2[-1] * 2 % MOD)
	ans = 0
	for i in range(N):
		if len(es[i]) == 1:
			continue
		ans += pow2[N - 1] - 1
		c = 0
		for to in es[i]:
			if cs[to] > cs[i]:
				continue
			c += cs[to]
			ans -= pow2[cs[to]] - 1
		ans -= pow2[N - c - 1] - 1
	ans *= pow(pow2[N], MOD - 2, MOD)
	print(ans % MOD)
solve()


from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 6)

def ext_euc(a, b):
	if b == 0:
		return (1, 0, a)
	(y, x, v) = ext_euc(b, a % b)
	y -= a // b * x
	return (x, y, v)

def mod_inv(a, mod):
	(x, _, _) = ext_euc(a, mod)
	return x % mod

def main():
	MOD = 10 ** 9 + 7
	N = int(input())
	adj = defaultdict(list)
	for _ in range(N - 1):
		(A, B) = list(map(lambda x: int(x) - 1, input().split()))
		adj[A].append(B)
		adj[B].append(A)
	pow_2 = [1 for _ in range(N + 1)]
	for i in range(1, N + 1):
		pow_2[i] = pow_2[i - 1] * 2 % MOD
	node_num = defaultdict(int)

	def dfs(node=0, parent=None):
		child_list = [n for n in adj[node] if n != parent]
		if len(child_list) == 0:
			node_num[node, parent] = N - 1
			node_num[parent, node] = 1
			return 1
		n_descendant = 1
		for child in child_list:
			n_descendant += dfs(child, node)
		if parent is not None:
			node_num[node, parent] = N - n_descendant
			node_num[parent, node] = n_descendant
		return n_descendant
	dfs()
	numer = 0
	for node in range(N):
		if len(adj[node]) <= 1:
			continue
		cnt_not = 0
		for dir_node in adj[node]:
			cnt_not += pow_2[node_num[node, dir_node]]
		cnt_not -= len(adj[node]) - 1
		numer += pow_2[N - 1] - cnt_not
	denom = pow_2[N]
	print(numer * mod_inv(denom, MOD) % MOD)
main()


import sys
sys.setrecursionlimit(500000)
input = sys.stdin.readline
N = int(input())
MOD = pow(10, 9) + 7
beki = [-1] * (N + 1)
beki[0] = 1
beki[1] = 2
for i in range(2, N + 1):
	beki[i] = beki[i - 1] * 2 % MOD
G = [[] for _ in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	G[a].append(b)
	G[b].append(a)
ans = 0

def dfs(v, p):
	global ans
	res = 1
	ts = []
	for u in G[v]:
		if u == p:
			continue
		t = dfs(u, v)
		res += t
		ts.append(t)
	if p != -1:
		ts.append(N - res)
	now = beki[N - 1] - 1
	for x in ts:
		now -= beki[x] - 1
	ans = (ans + now) % MOD
	return res
dfs(0, -1)
ALL = pow(2, N, MOD)
ans = ans * pow(ALL, MOD - 2, MOD) % MOD
print(ans)


import sys

def dfs1(root, links):
	parent = [0] * n
	subtree_count = [{} for _ in range(n)]
	q = [(root, -1, 0)]
	while q:
		(v, p, t) = q.pop()
		if t == 0:
			parent[v] = p
			q.append((v, p, 1))
			for u in links[v]:
				if u == p:
					continue
				q.append((u, v, 0))
		elif p != -1:
			subtree_count[p][v] = sum(subtree_count[v].values()) + 1
	return (parent, subtree_count)

def dfs2(root, parent, subtree_count, d2, d2s):
	ans = 0
	q = [(root, 0)]
	while q:
		(v, pc) = q.pop()
		if len(subtree_count[v]) == 0:
			continue
		p = parent[v]
		(children, st_counts) = list(map(list, list(zip(*list(subtree_count[v].items())))))
		children.append(p)
		st_counts.append(pc)
		cl = len(st_counts)
		ct = sum(st_counts)
		for (u, stc) in list(subtree_count[v].items()):
			q.append((u, ct - stc + 1))
		if cl == 1:
			continue
		tmp = 0
		for stc in st_counts:
			tmp = (tmp + d2s[ct - stc]) % MOD
		tmp = (tmp - d2s[ct] * (cl - 1)) % MOD
		ans = (ans + (1 - tmp) * d2) % MOD
	return ans
n = int(input())
links = [set() for _ in range(n)]
for line in sys.stdin:
	(a, b) = list(map(int, line.split()))
	a -= 1
	b -= 1
	links[a].add(b)
	links[b].add(a)
root = 0
MOD = 10 ** 9 + 7
d2 = 500000004
d2s = [1]
for i in range(n):
	d2s.append(d2s[-1] * d2 % MOD)
(parent, subtree_count) = dfs1(root, links)
ans = dfs2(root, parent, subtree_count, d2, d2s)
print(ans)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def MI1():
	return map(int1, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def main():

	def dfs(u=0, pu=-1):
		res = 1
		for cu in to[u]:
			if cu == pu:
				continue
			ret = dfs(cu, u)
			children_size[u].append(ret)
			res += ret
		return res
	md = 10 ** 9 + 7
	n = II()
	to = [[] for _ in range(n)]
	for _ in range(n - 1):
		(a, b) = MI1()
		to[a].append(b)
		to[b].append(a)
	half = pow(2, md - 2, md)
	exp_half = [1, half]
	for _ in range(n):
		exp_half.append(exp_half[-1] * half % md)
	children_size = [[] for _ in range(n)]
	dfs()
	ans = 0
	noblack = exp_half[n - 1]
	for cs in children_size:
		if not cs:
			continue
		sum_cs = sum(cs)
		if sum_cs != n - 1:
			cs.append(n - 1 - sum_cs)
		onlyone = 0
		for child_size in cs:
			onlyone += (1 - exp_half[child_size]) * exp_half[n - 1 - child_size]
		ans += (1 - noblack - onlyone) * half
		ans %= md
	print(ans)
main()


import sys
input = sys.stdin.readline
N = int(input())
E = [[] for i in range(N + 1)]
for i in range(N - 1):
	(x, y) = map(int, input().split())
	E[x].append(y)
	E[y].append(x)
mod = 10 ** 9 + 7
from collections import deque
Q = deque()
USE = [0] * (N + 1)
Q.append(1)
H = [0] * (N + 1)
H[1] = 1
USE[1] = 1
while Q:
	x = Q.pop()
	for to in E[x]:
		if USE[to] == 0:
			USE[to] = 1
			H[to] = H[x] + 1
			Q.append(to)
EH = [(h, ind + 1) for (ind, h) in enumerate(H[1:])]
EH.sort(reverse=True)
COME = [1] * (N + 1)
USE = [0] * (N + 1)
for (h, ind) in EH:
	USE[ind] = 1
	for to in E[ind]:
		if USE[to] == 0:
			COME[to] += COME[ind]
ANS = 0
POW2 = [1]
for i in range(N + 1):
	POW2.append(POW2[-1] * 2 % mod)
for i in range(1, N + 1):
	SCORE = []
	for j in E[i]:
		if COME[j] < COME[i]:
			SCORE.append(COME[j])
	if sum(SCORE) < N - 1:
		SCORE.append(N - sum(SCORE) - 1)
	AV = 1
	for s in SCORE:
		AV += POW2[s] - 1
	ANS += POW2[N - 1] - AV
print(ANS * pow(POW2[N], mod - 2, mod) % mod)


from collections import deque

def topological_sort_tree(tree: list, root) -> list:
	n = len(tree)
	ans = [root]
	visited = [False] * n
	visited[root] = True
	q = deque([root])
	while q:
		par = q.popleft()
		for child in tree[par]:
			if visited[child]:
				continue
			visited[child] = True
			q.append(child)
			ans.append(child)
	return ans
n = int(input())
info = [list(map(int, input().split())) for i in range(n - 1)]
MOD = 10 ** 9 + 7
tree = [[] for i in range(n)]
for (a, b) in info:
	a -= 1
	b -= 1
	tree[a].append(b)
	tree[b].append(a)
inv2 = pow(2, MOD - 2, MOD)
ans = 0
tp_sorted = topological_sort_tree(tree, 0)[::-1]
dp = [0] * n
for v in tp_sorted:
	sum_ = 0
	w_p = []
	for nxt_v in tree[v]:
		sum_ += dp[nxt_v]
		if dp[nxt_v] != 0:
			w_p.append(pow(inv2, dp[nxt_v], MOD))
	dp[v] = sum_ + 1
	if len(tree[v]) == 1:
		continue
	if n - dp[v] != 0:
		w_p.append(pow(inv2, n - dp[v], MOD))
	res = 1
	all_w = 1
	for val in w_p:
		all_w *= val
		all_w %= MOD
	res -= all_w
	res %= MOD
	for val in w_p:
		b = 1 - val
		res -= all_w * pow(val, MOD - 2, MOD) * b
		res %= MOD
	ans += res * inv2
	ans %= MOD
print(ans % MOD)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	graph[a - 1].append(b - 1)
	graph[b - 1].append(a - 1)

def extgcd(a, b):
	r = [1, 0, a]
	w = [0, 1, b]
	while w[2] != 1:
		q = r[2] // w[2]
		r2 = w
		w2 = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
		r = r2
		w = w2
	return [w[0], w[1]]

def mod_inv(a, m=mod):
	x = extgcd(a, m)[0]
	return (m + x % m) % m
N2 = [1]
n = 1
for _ in range(N + 1):
	n = n * 2 % mod
	N2.append(n)
Weight = [[] for _ in range(N)]
checked = [False] * N

def dfs(p):
	checked[p] = True
	downs = 0
	for np in graph[p]:
		if not checked[np]:
			downscore = dfs(np)
			Weight[p].append(N - downscore)
			Weight[np].append(downscore)
			downs += N - downscore
	return N - (downs + 1)
dfs(0)
a = 0
for n in range(N):
	if len(Weight[n]) == 1:
		continue
	c = N2[N - 1] - 1
	for w in Weight[n]:
		c = (c - N2[w] + 1) % mod
	a = (a + c) % mod
ans = a * mod_inv(N2[N]) % mod
print(ans)


import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)
n = int(input())
E = [[] for _ in range(n)]
mod = 10 ** 9 + 7
for i in range(n - 1):
	(a, b) = [int(x) for x in input().split()]
	E[a - 1].append((b - 1, i))
	E[b - 1].append((a - 1, i))
X = [0] * n

def dfs(u, e):
	num = 1
	for (v, c) in E[u]:
		if c != e:
			num += dfs(v, c)
	X[e] = num
	return num
dfs(0, -1)
I = [1]
inv = pow(2, mod - 2, mod)
for i in range(n):
	I.append(I[-1] * inv % mod)
ans = 0
for i in range(n):
	x = X[i]
	ans += (1 - I[x]) * (1 - I[n - x]) % mod
ans -= n * I[1]
ans += 1 - I[n]
ans %= mod
print(ans)


from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
g = [[] for _ in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	g[a].append(b)
	g[b].append(a)
mod = 10 ** 9 + 7
par = [0] * (n + 1)
order = []
stk = deque()
stk.append(1)
while stk:
	v = stk.pop()
	order.append(v)
	for x in g[v]:
		if x == par[v]:
			continue
		par[x] = v
		stk.append(x)
rev = pow(2, mod - 2, mod)
po2_inv = [1] * (n + 1)
size = [1] * (n + 1)
for (i, y) in enumerate(order[::-1], 1):
	p = par[y]
	size[p] += size[y]
	po2_inv[i] = po2_inv[i - 1] * rev % mod
ans = 1
for i in size[2:]:
	ans += (1 - po2_inv[i] - po2_inv[n - i] + po2_inv[n]) % mod
ans -= po2_inv[n] + n * po2_inv[1]
ans %= mod
print(ans)


from collections import deque
LARGE = 10 ** 9 + 7

def solve(n, a_list, b_list):
	g = [[] for _ in range(n)]
	for i in range(n - 1):
		a = a_list[i] - 1
		b = b_list[i] - 1
		g[a].append(b)
		g[b].append(a)
	parent = [-1] * n
	children = [[] for _ in range(n)]
	depth = [0] * n
	queue = deque([0])
	while len(queue) > 0:
		p = queue.popleft()
		for q in g[p]:
			if q == parent[p]:
				continue
			parent[q] = p
			children[p].append(q)
			depth[q] = depth[p] + 1
			queue.append(q)
	weight = [1] * n
	deeper = list(sorted([[i, depth[i]] for i in range(n)], key=lambda x: x[1], reverse=True))
	for (i, _) in deeper:
		for j in children[i]:
			weight[i] += weight[j]
	res_array = [0] * n
	for i in range(1, n):
		for j in children[i]:
			res_array[n - 1 - weight[j]] += 1
		res_array[weight[i] - 1] += 1
		res_array[n - 1] -= len(children[i])
	for j in children[0]:
		res_array[n - 1 - weight[j]] += 1
	res_array[n - 1] -= len(children[0]) - 1
	res_a = pow(2, n - 1, LARGE) * n
	res_a %= LARGE
	for i in range(n):
		res_a -= pow(2, n - i - 1, LARGE) * res_array[i]
		res_a %= LARGE
	res_b = pow(2, n, LARGE)
	res = res_a * pow(res_b, LARGE - 2, LARGE) % LARGE
	return res

def main():
	n = int(input())
	a_list = [0] * (n - 1)
	b_list = [0] * (n - 1)
	for i in range(n - 1):
		(a, b) = map(int, input().split())
		a_list[i] = a
		b_list[i] = b
	res = solve(n, a_list, b_list)
	print(res)

def test():
	assert solve(3, [1, 2], [2, 3]) == 125000001
	assert solve(4, [1, 2, 3], [2, 3, 4]) == 375000003
	assert solve(4, [1, 1, 1], [2, 3, 4]) == 250000002
test()
main()


from sys import stdin, setrecursionlimit
from collections import deque
setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
pow2 = [1] * (N + 1)
for i in range(N):
	pow2[i + 1] = pow2[i] * 2 % MOD
order = []
parent = [-1] * N
stack = deque([0])
while stack:
	v = stack.pop()
	order.append(v)
	for nv in G[v]:
		if parent[v] != nv:
			parent[nv] = v
			stack.append(nv)
numer = 0
nums = [0] * N
for v in reversed(order):
	tmp = 1
	for nv in G[v]:
		if parent[v] != nv:
			nums[v] += nums[nv] + 1
			tmp += pow2[nums[nv] + 1] - 1
	tmp += pow2[N - nums[v] - 1] - 1
	numer = (numer + pow2[N - 1] - tmp) % MOD
denom = pow2[N]
ans = numer * pow(denom, MOD - 2, MOD) % MOD
print(ans)


import sys
sys.setrecursionlimit(200200)
input = sys.stdin.readline
MOD = 10 ** 9 + 7
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N - 1)]
G = [[] for _ in range(N)]
for (i, (a, b)) in enumerate(AB):
	a -= 1
	b -= 1
	G[a].append((b, i))
	G[b].append((a, i))
P = [0] * N
visited = [False] * N
visited[0] = True

def dfs(x, i):
	e = 1
	for (v, c) in G[x]:
		if not visited[v]:
			visited[v] = True
			e += dfs(v, c)
	P[i] = e
	return e
dfs(0, -1)
W = [1] * (N + 1)
inv_2 = pow(2, MOD - 2, MOD)
for i in range(N):
	W[i + 1] = W[i] * inv_2 % MOD
ans = (W[N] + 1) * (N - 1) % MOD
for i in range(N - 1):
	ans -= W[P[i]] + W[N - P[i]]
	ans %= MOD
print((ans - inv_2 * N - W[N] + 1) % MOD)


import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7

def MOD_inv(a):
	b = MOD
	u = 1
	v = 0
	while b > 0:
		t = a // b
		a -= t * b
		(a, b) = (b, a)
		u -= t * v
		(u, v) = (v, u)
	u = u % MOD
	if u < 0:
		u += MOD
	return u

def cntNode(G, C, crr, pre):
	s = 0
	for (i, nxt) in enumerate(G[crr]):
		if nxt == pre:
			continue
		else:
			C[crr][i] = cntNode(G, C, nxt, crr)
			s += C[crr][i]
	return s + 1

def main():
	n = int(input())
	G = [[] for _ in range(n)]
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		(a, b) = (a - 1, b - 1)
		G[a].append(b)
		G[b].append(a)
	C = [[-1] * len(G[i]) for i in range(n)]
	idx = -1
	for i in range(n):
		if len(G[i]) == 1:
			idx = i
			break
	cntNode(G, C, idx, -1)
	for i in range(n):
		idx = -1
		s = 0
		for (j, v) in enumerate(C[i]):
			if v == -1:
				idx = j
			else:
				s += v
		if idx != -1:
			C[i][idx] = n - 1 - s
	s = 0
	pows = [0] * (n + 1)
	pows[0] = 1
	for i in range(1, n + 1):
		pows[i] = 2 * pows[i - 1] % MOD
	for i in range(n):
		p = pows[n - 1]
		for v in C[i]:
			p -= pows[v] - 1
		p -= 1
		p %= MOD
		s += p
		s %= MOD
	print(s * MOD_inv(pows[n]) % MOD)

def __starting_point():
	main()
__starting_point()


import sys
sys.setrecursionlimit(300000)
MOD = 1000000007

def calc_fraction_mod(numerator, denominator):
	inv = pow(denominator, MOD - 2, MOD)
	return numerator * inv % MOD

def solve(N: int, A: 'List[int]', B: 'List[int]'):
	conns = [[] for _ in range(N)]
	for i in range(N - 1):
		conns[A[i] - 1].append(B[i] - 1)
		conns[B[i] - 1].append(A[i] - 1)
	pows = []
	for i in range(N + 1):
		pows.append(pow(2, i, MOD))
	num = [0]
	visited = [False] * N

	def dfs(idx):
		visited[idx] = True
		children = 0
		subs = []
		for c in conns[idx]:
			if visited[c]:
				continue
			sub = dfs(c)
			children += sub
			subs.append(sub)
		subs.append(N - children - 1)
		tmp = pows[N - 1]
		tmp -= 1
		for sub in subs:
			tmp -= pows[sub] - 1
		num[0] += tmp
		return children + 1
	dfs(0)
	deno = pows[N]
	num = num[0]
	ret = calc_fraction_mod(num, deno)
	print(ret)
	return

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	A = [int()] * (N - 1)
	B = [int()] * (N - 1)
	for i in range(N - 1):
		A[i] = int(next(tokens))
		B[i] = int(next(tokens))
	solve(N, A, B)
main()


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
par = [-1] * n
depth = [-1] * n
sizesub = [1 for _ in range(n)]
black = [0 for _ in range(n)]
root = 0
stack = [root]
while stack:
	v = stack.pop()
	if depth[v] == -1:
		if v == root:
			depth[v] = 0
		else:
			depth[v] = depth[par[v]] + 1
			stack.append(v)
		for w in g[v]:
			if depth[w] == -1:
				par[w] = v
				stack.append(w)
	else:
		sizesub[par[v]] += sizesub[v]
		black[par[v]] += pow(2, sizesub[v], mod) - 1
cnt = 0
for i in range(n):
	tmp = pow(2, n - 1, mod) - pow(2, n - sizesub[i], mod) - black[i]
	tmp %= mod
	cnt += tmp
	cnt %= mod

def inv(a, mod):
	r = [1, 0, a]
	w = [0, 1, mod]
	while w[2] != 1:
		q = r[2] // w[2]
		r_new = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
		r = w
		w = r_new
	(x, y) = (w[0], w[1])
	return (mod + x % mod) % mod
print(inv(pow(2, n, mod), mod) * cnt % mod)


import sys
sys.setrecursionlimit(10 ** 7)
P = 10 ** 9 + 7
N = int(input())
edges = [[] for i in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	edges[a - 1].append((b - 1, i))
	edges[b - 1].append((a - 1, i))
L = [0] * N

def dfs(cur, x):
	res = 1
	for i in edges[cur]:
		if i[1] != x:
			res += dfs(i[0], i[1])
	L[x] = res
	return res
dfs(0, -1)
L2 = [1]
i2 = pow(2, P - 2, P)
for i in range(N):
	L2.append(L2[-1] * i2 % P)
cnt = 0
for i in L:
	cnt += (1 - L2[i]) * (1 - L2[N - i])
print((-N * i2 - L2[-1] + cnt + 1) % P)


from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
	n = I()
	v = [[] for i in range(n)]
	for i in range(n - 1):
		(a, b) = LI()
		a -= 1
		b -= 1
		v[a].append(b)
		v[b].append(a)
	d = [0] * n
	d[0] = 1
	q = deque([0])
	p = [None] * n
	while q:
		x = q.popleft()
		nd = d[x] + 1
		for y in v[x]:
			if not d[y]:
				d[y] = nd
				p[y] = x
				q.append(y)
	V = list(range(n))
	V.sort(key=lambda x: -d[x])
	t = [1] * n
	for x in V[:-1]:
		t[p[x]] += t[x]
	ans = n
	for x in range(n):
		tx = t[x]
		for y in v[x]:
			ty = t[y]
			if tx < ty:
				ans += pow(2, t[0] - tx, mod) - 1
			else:
				ans += pow(2, ty, mod) - 1
		ans %= mod
	print((n * pow(2, mod - 2, mod) - ans * pow(2, (mod - 2) * n % (mod - 1), mod)) % mod)
	return
solve()


p = 1000000007
N = int(input())
T = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = (int(x) - 1 for x in input().split())
	T[a].append(b)
	T[b].append(a)
P = [-1] * N
P[0] = 0
Q = [0]
for i in range(N):
	q = Q[i]
	for adj in T[q]:
		if 0 <= P[adj]:
			continue
		P[adj] = q
		Q.append(adj)
ST = [[] for _ in range(N)]
for q in Q[N - 1:0:-1]:
	s = sum(ST[q]) + 1
	ST[P[q]].append(s)
	ST[q].append(N - s)
B = [1] * N
B[-1] = pow(1 << N - 1, p - 2, p)
for i in range(N - 1, 0, -1):
	B[i - 1] = B[i] * 2 % p
H = [0] * N
ans = 0
for S in ST:
	ans += B[1] * ((1 - B[-1] - sum([B[N - 1 - s] * (1 - B[s]) % p for s in S])) % p)
	ans %= p
print(ans)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def solve():
	MOD = 10 ** 9 + 7
	N = int(input())
	adjL = [[] for _ in range(N)]
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		(a, b) = (a - 1, b - 1)
		adjL[a].append(b)
		adjL[b].append(a)
	sizeSubtrees = [0] * N
	sizeAdjss = [[] for _ in range(N)]

	def dfs(vNow, vPar):
		sizeSubtrees[vNow] = 1
		for v2 in adjL[vNow]:
			if v2 == vPar:
				continue
			s = dfs(v2, vNow)
			sizeAdjss[vNow].append(s)
			sizeSubtrees[vNow] += s
		sizeAdjss[vNow].append(N - sizeSubtrees[vNow])
		return sizeSubtrees[vNow]
	dfs(0, -1)

	def getPows(base, n, MOD):
		pows = [1] * (n + 1)
		for x in range(1, n + 1):
			pows[x] = pows[x - 1] * base % MOD
		return pows
	pow2s = getPows(2, N, MOD)
	nums = [0] * N
	for v in range(N):
		num = pow2s[N - 1] - 1
		for sizeAdj in sizeAdjss[v]:
			num -= pow2s[sizeAdj] - 1
			num %= MOD
		nums[v] = num
	ans = sum(nums) % MOD * pow(pow2s[N], MOD - 2, MOD) % MOD
	print(ans)
solve()


n = int(input())
mod = 10 ** 9 + 7
import sys
input = sys.stdin.readline
from collections import deque
graph = [[] for _ in range(n + 1)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	graph[a].append(b)
	graph[b].append(a)
ini = 0

def calc(a, b):
	return a + b

def calc1(c, p):
	p_num = ini
	for i in graph[c]:
		if i == p:
			continue
		p_num = calc(p_num, dp1[i])
	dp1[c] = (p_num + 1) % mod

def calc2(p):
	arr = [dp1[c] if c != parent[p] else dp2[p] for c in graph[p]]
	left = [ini]
	for i in arr[:-1]:
		left.append(calc(left[-1], i))
	right = [ini]
	for i in arr[:0:-1]:
		right.append(calc(right[-1], i))
	right = right[::-1]
	prod = []
	for (a, b) in zip(left, right):
		prod.append(calc(a, b))
	for (c, x) in zip(graph[p], prod):
		if c != parent[p]:
			dp2[c] = (x + 1) % mod
root = 1
order = []
parent = [0] * (n + 1)
stack = deque()
stack.append(root)
while stack:
	x = stack.pop()
	order.append(x)
	for y in graph[x]:
		if y == parent[x]:
			continue
		stack.append(y)
		parent[y] = x
dp1 = [0] * (n + 1)
for i in order[::-1]:
	calc1(i, parent[i])
dp2 = [0] * (n + 1)
for i in order:
	calc2(i)
ans = 0
for i in range(1, n + 1):
	gr = graph[i]
	if len(gr) == 1:
		continue
	tmp = pow(2, n - 1, mod) - 1
	for v in gr:
		if v == parent[i]:
			exp_num = dp2[i]
		else:
			exp_num = dp1[v]
		tmp = (tmp - (pow(2, exp_num, mod) - 1)) % mod
	ans = (ans + tmp) % mod
ans = ans * pow(pow(2, n, mod), mod - 2, mod) % mod
print(ans)


import sys
sys.setrecursionlimit(2 * 10 ** 5)
input = sys.stdin.readline

def calc_counts(n, edges):
	counts = [0] * n
	seen = [False] * n
	dfs(0, edges, seen, counts)
	return counts

def dfs(node, edges, seen, counts):
	count = 1
	seen[node] = True
	for to in edges[node]:
		if seen[to]:
			continue
		count += dfs(to, edges, seen, counts)
	counts[node] = count
	return count

def calc_blank(node, counts: list, edges, all, mod=10 ** 9 + 7):
	n = len(counts)
	paths = edges[node]
	if len(paths) <= 1:
		return 0
	base = counts[node]
	result = all - 1
	for v in paths:
		count = counts[v]
		if count > base:
			count = n - base
		result -= pow(2, count, mod) - 1
		result %= mod
	return result

def main():
	mod = 10 ** 9 + 7
	n = int(input())
	edges = [[] for _ in range(n)]
	for _ in range(n - 1):
		(a, b) = list(map(int, input().split()))
		edges[a - 1].append(b - 1)
		edges[b - 1].append(a - 1)
	counts = calc_counts(n, edges)
	all = pow(2, n - 1, mod)
	blanks = 0
	for node in range(n):
		blank = calc_blank(node, counts, edges, all)
		blanks += blank
		blanks %= mod
	inv_denominator = pow(pow(2, n, mod), mod - 2, mod)
	ans = blanks * inv_denominator % mod
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return list(map(int, input().split()))

def main():
	mod = 10 ** 9 + 7
	import queue
	N = I()
	adj = [[] for _ in range(N)]
	for i in range(N - 1):
		(x, y) = MI()
		x -= 1
		y -= 1
		adj[x].append(y)
		adj[y].append(x)
	POW = [1]
	for _ in range(N + 5):
		temp = POW[-1]
		POW.append(temp * 2 % mod)
	deg = [0] * N
	for i in range(N):
		deg[i] = len(adj[i])
	L = [[] for _ in range(N)]
	looked = [0] * N
	used = [0] * N
	q = queue.Queue()
	for v in range(N):
		if len(adj[v]) == 1:
			q.put(v)
			L[v].append(0)
			looked[v] = 1
	ans = [0] * N
	while not q.empty():
		v = q.get()
		S = sum(L[v])
		rem = N - 1 - S
		temp = POW[N - 1]
		temp -= 1
		for s in L[v]:
			temp -= POW[s] - 1
			temp %= mod
		temp -= POW[rem] - 1
		temp %= mod
		ans[v] = temp
		used[v] = 1
		for nv in adj[v]:
			if used[nv] == 0:
				L[nv].append(S + 1)
			if looked[nv] == 0:
				if len(L[nv]) >= deg[nv] - 1:
					q.put(nv)
					looked[nv] = 1
	y = sum(ans)
	x = POW[N]
	res = y * pow(x, mod - 2, mod) % mod
	print(res)
main()


import sys
input = sys.stdin.readline
from collections import deque

def r(a):
	for i in range(1, 10001):
		if i and a * i % mod <= 10000:
			return str(a * i % mod) + '/' + str(i)
		if i and -a * i % mod <= 10000:
			return str(-(-a * i % mod)) + '/' + str(i)
	return a
N = int(input())
X = [[] for i in range(N)]
for i in range(N - 1):
	(x, y) = map(int, input().split())
	X[x - 1].append(y - 1)
	X[y - 1].append(x - 1)
i0 = min([i for i in range(N) if len(X[i]) == 1])
P = [-1] * N
Q = deque([i0])
R = []
while Q:
	i = deque.popleft(Q)
	R.append(i)
	for a in X[i]:
		if a != P[i]:
			P[a] = i
			X[a].remove(i)
			deque.append(Q, a)
mod = 10 ** 9 + 7
inv2 = (mod + 1) // 2
A = [1] * N
B = [1] * N
for i in R[::-1]:
	s = inv2
	for j in X[i]:
		s = s * A[j] % mod
	A[i] = s
for i in R[1:]:
	if P[i] == i0:
		B[i] = A[i0] * pow(A[i], mod - 2, mod) % mod
	else:
		B[i] = B[P[i]] * A[P[i]] * pow(A[i], mod - 2, mod) % mod
ans = 0
for i in range(N):
	s = B[i]
	t = 1 + (1 - B[i]) * pow(B[i], mod - 2, mod)
	for j in X[i]:
		s = s * A[j] % mod
		t = (t + (1 - A[j]) * pow(A[j], mod - 2, mod)) % mod
	ans = (ans + 1 - s * t) % mod
print(ans * inv2 % mod)


n = int(input())
G = [[] for _ in range(n)]
mod = 10 ** 9 + 7
for _ in range(n - 1):
	(a, b) = map(lambda x: int(x) - 1, input().split())
	G[a - 1].append(b - 1)
	G[b - 1].append(a - 1)
stack = [0]
depth = [-1] * n
depth[0] = 0
while stack:
	v = stack.pop()
	d = depth[v]
	for nv in G[v]:
		if depth[nv] >= 0:
			continue
		depth[nv] = depth[v] + 1
		stack.append(nv)
d_to_i = [[] for _ in range(n)]
for i in range(n):
	d_to_i[depth[i]].append(i)
data = [[] for _ in range(n)]
for d in range(n - 1, -1, -1):
	for v in d_to_i[d]:
		for nv in G[v]:
			if depth[nv] < depth[v]:
				continue
			if data[nv]:
				data[v].append(n - data[nv][-1])
		if data[v]:
			data[v].append(n - 1 - sum(data[v]))
		else:
			data[v].append(n - 1)
ans = 0
two = [1]
for i in range(n):
	two.append(two[-1] * 2 % mod)
for i in range(n):
	now = two[n - 1] - 1
	for x in data[i]:
		now -= two[x] - 1
		now %= mod
	ans += now
ans *= pow(two[n], mod - 2, mod)
ans %= mod
print(ans)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7
N = int(input())
vec = [[] for _ in range(N)]
for _ in range(N - 1):
	(A, B) = map(int, input().split())
	vec[A - 1].append(B - 1)
	vec[B - 1].append(A - 1)
own_size = [0] * N
sub_size = [[] for _ in range(N)]
stack = [(0, -1)]
for i in range(N):
	(cur, pre) = stack[i]
	for nex in vec[cur]:
		if nex != pre:
			stack.append((nex, cur))
while stack:
	(cur, pre) = stack.pop()
	if pre != -1:
		sub_size[pre].append(own_size[cur] + 1)
		own_size[pre] += own_size[cur] + 1
	if own_size[cur] != N - 1:
		sub_size[cur].append(N - 1 - own_size[cur])
fac = [1]
inv = [1]
div = pow(2, mod - 2, mod)
for _ in range(N):
	fac.append(fac[-1] * 2 % mod)
	inv.append(inv[-1] * div % mod)
ret = 0
for i in range(N):
	if len(sub_size[i]) < 2:
		continue
	(a, b) = (1, 1)
	for ss in sub_size[i]:
		a *= inv[ss]
		b += fac[ss] - 1
		a %= mod
		b %= mod
	ret += (1 - a * b) % mod
	ret %= mod
ret = ret * div % mod
print(ret)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7

def main():
	N = int(readline())
	m = map(int, read().split())
	AB = zip(m, m)
	graph = [[] for _ in range(N + 1)]
	for (a, b) in AB:
		graph[a].append(b)
		graph[b].append(a)
	root = 1
	stack = [root]
	parent = [0] * (N + 1)
	order = []
	while stack:
		node = stack.pop()
		order.append(node)
		for child in graph[node]:
			if parent[node] == child:
				continue
			parent[child] = node
			stack.append(child)
	pow_inv = [1] * (N + 1)
	for i in range(N):
		pow_inv[i + 1] = pow_inv[i] * 2 % MOD
	node_count = [1] * (N + 1)
	for v in order[::-1]:
		node_count[parent[v]] += node_count[v]
	tmp = 0
	for target_node in range(1, N + 1):
		child_par_sum = 0
		for child in graph[target_node]:
			if child == parent[target_node]:
				continue
			child_par_sum += node_count[child]
			tmp += pow_inv[node_count[child]] - 1
		parent_par_sum = N - 1 - child_par_sum
		tmp += pow_inv[parent_par_sum] - 1
		tmp %= MOD
	y = (pow_inv[N - 1] - 1) * N - tmp
	y %= MOD
	x = pow(pow_inv[N], MOD - 2, MOD)
	z = x * y % MOD
	print(z)
	return
main()


import sys
input = sys.stdin.readline
from collections import deque
N = int(input())
X = [[] for i in range(N)]
for i in range(N - 1):
	(x, y) = map(int, input().split())
	X[x - 1].append(y - 1)
	X[y - 1].append(x - 1)
i0 = min([i for i in range(N) if len(X[i]) == 1])
P = [-1] * N
Q = deque([i0])
R = []
while Q:
	i = deque.popleft(Q)
	R.append(i)
	for a in X[i]:
		if a != P[i]:
			P[a] = i
			X[a].remove(i)
			deque.append(Q, a)
mod = 10 ** 9 + 7
inv2 = (mod + 1) // 2
A = [1] * N
for i in R[::-1]:
	s = 0
	for j in X[i]:
		A[i] += A[j]
ans = 0
for i in range(N):
	s = pow(inv2, N - A[i], mod)
	t = 1 + (1 - pow(inv2, N - A[i], mod)) * pow(2, N - A[i], mod)
	for j in X[i]:
		s = s * pow(inv2, A[j], mod) % mod
		t = (t + (1 - pow(inv2, A[j], mod)) * pow(2, A[j], mod)) % mod
	ans = (ans + 1 - s * t) % mod
print(ans * inv2 % mod)


n = int(input())
mod = 10 ** 9 + 7
edge = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	edge[a].append(b)
	edge[b].append(a)
inv2 = [1] * (n + 1)
t = pow(pow(2, n, mod), mod - 2, mod)
for i in range(n, -1, -1):
	inv2[i] = t
	t *= 2
	t %= mod
import sys
sys.setrecursionlimit(10 ** 6)
dep = [-1 for i in range(n + 1)]
ans = [0]

def f(a):
	return inv2[n - a] * (1 - inv2[a]) % mod

def dfs(s, d):
	dep[s] = d
	tmp = inv2[1] - inv2[n]
	y = 0
	for i in edge[s]:
		if dep[i] == -1:
			x = dfs(i, d + 1)
			tmp -= f(x)
			y += x
	if y == 0:
		return 1
	tmp -= f(n - y - 1)
	ans[0] += tmp
	ans[0] %= mod
	return y + 1
dfs(1, 0)
print(ans[0])


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input())
g = [[] for _ in range(n)]
pow2 = [0 for _ in range(n + 1)]
pow2[0] = 1
for i in range(n):
	pow2[i + 1] = pow2[i] * 2 % mod
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
depth = [-1] * n
ko_all = [0 for _ in range(n)]
ko_only = [0 for _ in range(n)]
depth[0] = 0
stack = [0]
while stack:
	v = stack.pop()
	if any((depth[w] == -1 for w in g[v])):
		stack.append(v)
	for w in g[v]:
		if depth[w] == -1:
			depth[w] = depth[v] + 1
			stack.append(w)
		elif depth[w] > depth[v]:
			ko_all[v] += ko_all[w] + 1
			ko_only[v] += pow2[ko_all[w] + 1] - 1
cnt = 0
for i in range(n):
	tmp = pow2[n - 1] - 1 - (pow2[n - 1 - ko_all[i]] - 1) - ko_only[i]
	tmp %= mod
	cnt += tmp
	cnt %= mod

def inv(a, mod):
	r = [1, 0, a]
	w = [0, 1, mod]
	while w[2] != 1:
		q = r[2] // w[2]
		r_new = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
		r = w
		w = r_new
	(x, y) = (w[0], w[1])
	return (mod + x % mod) % mod
print(inv(pow2[n], mod) * cnt % mod)


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
N = int(input())
MOD = 10 ** 9 + 7
tree = [[] for i in range(N + 1)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	tree[a].append(b)
	tree[b].append(a)
(root, par) = (1, 0)
sizes = [0] * (N + 1)
order = [[root, par]]

def calc_nums(node, par):
	global sizes
	global order
	if sizes[node] > 0:
		return sizes[node]
	children = tree[node]
	res = 1
	for child in children:
		if child == par:
			continue
		order.append([child, node])
		res += calc_nums(child, node)
	sizes[node] = res
	return res
_ = calc_nums(root, par)
prod2 = [1]
for i in range(N):
	prod2.append(prod2[-1] * 2 % MOD)
demo = 0
div = prod2[N]
base = prod2[N - 1] - 1
for (node, par) in order:
	children = tree[node]
	num = base
	num_par = N - 1
	for child in children:
		if child == par:
			continue
		s = sizes[child]
		num_par -= s
		num -= prod2[s] - 1
	num -= prod2[num_par] - 1
	demo += num
ans = demo * pow(div, MOD - 2, MOD) % MOD
print(ans)


import sys
sys.setrecursionlimit(200200)
mod = 10 ** 9 + 7
(N, *AB) = map(int, open(0).read().split())
E = [[] for _ in range(N + 1)]
for (i, (a, b)) in enumerate(zip(*[iter(AB)] * 2)):
	E[a - 1].append((b - 1, i))
	E[b - 1].append((a - 1, i))
X = [0] * N
visited = [False] * N
visited[0] = True

def dfs(u, i):
	res = 1
	for (v, c) in E[u]:
		if not visited[v]:
			visited[v] = True
			res += dfs(v, c)
	X[i] = res
	return res
dfs(0, -1)
I = [1] * (N + 1)
inv = pow(2, mod - 2, mod)
for i in range(N):
	I[i + 1] = I[i] * inv % mod
ans = (I[N] + 1) * (N - 1) - inv * N - I[N] + 1
for xe in range(N - 1):
	ans -= I[X[xe]] + I[N - X[xe]]
	ans %= mod
print(ans)


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7
N = int(input())
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(x, y) = map(int, input().split())
	edge[x].append(y)
	edge[y].append(x)
memo = [[] for _ in range(N + 1)]

def dfs(s, p=-1):
	sub_tree = []
	res = 1
	for t in edge[s]:
		if t == p:
			continue
		size = dfs(t, s)
		sub_tree.append(size)
		res += size
	if N != res:
		sub_tree.append(N - res)
	memo[s].extend(sub_tree)
	return res
dfs(1)
pow2 = [1] * (N + 1)
for i in range(1, N + 1):
	pow2[i] = pow2[i - 1] * 2 % mod
cnt = 0
for lis in memo[1:]:
	if len(lis) == 1:
		continue
	tmp = pow2[N - 1] - 1
	for x in lis:
		black = pow2[x] - 1
		tmp = (tmp - black + mod) % mod
	cnt = (cnt + tmp) % mod
div = pow2[N]
ans = cnt * pow(div, mod - 2, mod) % mod
print(ans)


from collections import deque
import sys
input = sys.stdin.readline

def dfs():
	stk1 = deque([0])
	stk2 = deque([])
	while stk1:
		v = stk1.pop()
		visited[v] = True
		stk2.append(v)
		for i in range(len(AL[v][CHILDREN])):
			u = AL[v][CHILDREN][i]
			if visited[u]:
				AL[v][CHILDREN][i] = None
				continue
			stk1.append(u)
	for i in range(n - 1, -1, -1):
		v = stk2[i]
		for u in AL[v][CHILDREN]:
			if u is None:
				continue
			AL[v][SIZE] += AL[u][SIZE]

def anaaki(v):
	ret = pow(2, n - 1, p) - 1
	for ch in AL[v][CHILDREN]:
		if ch is None:
			continue
		ret -= pow(2, AL[ch][SIZE], p) - 1
		ret %= p
	ret -= pow(2, n - AL[v][SIZE], p) - 1
	ret %= p
	return ret
n = int(input())
SIZE = 0
CHILDREN = 1
AL = [[1, []] for _ in range(n)]
visited = [False] * n
p = 10 ** 9 + 7
for i in range(n - 1):
	(a, b) = [int(x) - 1 for x in input().split()]
	AL[a][CHILDREN].append(b)
	AL[b][CHILDREN].append(a)
dfs()
numer = 0
for i in range(n):
	numer += anaaki(i)
	numer %= p
denom = pow(2, n, p)
print(numer * pow(denom, p - 2, p) % p)


import sys
sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : list(map(int, readline().split()))
nl = lambda : list(map(int, readline().split()))
n = ni()
G = [list() for _ in range(n)]
for _ in range(n - 1):
	(a, b) = nm()
	a -= 1
	b -= 1
	G[a].append(b)
	G[b].append(a)
mod = 10 ** 9 + 7
dub = [1] * (n + 1)
for i in range(n):
	dub[i + 1] = dub[i] * 2
	if dub[i + 1] > mod:
		dub[i + 1] -= mod
size = [1] * n

def dfs_depandsize(tree, v, p):
	for x in tree[v]:
		if x == p:
			continue
		size[v] += dfs_depandsize(tree, x, v)
	return size[v]
dfs_depandsize(G, 0, -1)
ans = 0
for v in range(n):
	c = 0
	res = 1
	for x in G[v]:
		if size[x] < size[v]:
			c += size[x]
			res += dub[size[x]] - 1
	res += dub[n - 1 - c] - 1
	res %= mod
	ans = (ans + dub[n - 1] - res) % mod
print(ans * pow(dub[n], mod - 2, mod) % mod)


import os
import sys
if os.getenv('LOCAL'):
	sys.stdin = open('_in.txt', 'r')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
IINF = 10 ** 18
MOD = 10 ** 9 + 7

def div_mod(a, b, mod):
	return a * pow(b, mod - 2, mod) % mod
N = int(sys.stdin.buffer.readline())
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N - 1)]
graph = [[] for _ in range(N)]
for (a, b) in AB:
	a -= 1
	b -= 1
	graph[a].append(b)
	graph[b].append(a)
root = 0
stack = [(0, None)]
hist = []
while stack:
	(v, parent) = stack.pop()
	hist.append((v, parent))
	for u in graph[v]:
		if u == parent:
			continue
		stack.append((u, v))
subtree_sizes = [0] * N
hist.reverse()
for (v, parent) in hist:
	ret = 0
	for u in graph[v]:
		if u == parent:
			continue
		ret += subtree_sizes[u]
	subtree_sizes[v] = ret + 1
pow2 = [1]
p = 1
for _ in range(N + 10):
	p = p * 2 % MOD
	pow2.append(p)
e_exp = 0
for v in range(N):
	for u in graph[v]:
		if v < u:
			continue
		s = min(subtree_sizes[v], subtree_sizes[u])
		t = N - s
		cnt = pow2[N]
		cnt -= pow2[t]
		cnt -= pow2[s]
		cnt += 1
		e_exp += cnt
		e_exp %= MOD
v_exp = e_exp + pow2[N] - 1
ans = div_mod(v_exp, pow2[N], MOD) - div_mod(N, 2, MOD)
ans %= MOD
print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(200000)
mod = 10 ** 9 + 7
n = int(input())
edge = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	edge[a - 1].append(b - 1)
	edge[b - 1].append(a - 1)
inf = 10 ** 6
Par = [inf] * n
Par[0] = -1
Chk = [0]
while Chk:
	c = Chk.pop()
	for next in edge[c]:
		if Par[next] == inf:
			Par[next] = c
			Chk.append(next)
C = [-1] * n

def ch(x):
	ret = 0
	if x != 0 and len(edge[x]) == 1:
		C[x] = 0
		return C[x]
	else:
		for e in edge[x]:
			if e == Par[x]:
				continue
			else:
				ret += ch(e) + 1
		C[x] = ret
		return C[x]
ch(0)
H = [0] * n
H[0] = 1
H[1] = pow(2, mod - 2, mod)
for i in range(2, n):
	H[i] = H[i - 1] * H[1] % mod
ans = 0
for i in range(n):
	if len(edge[i]) == 1:
		continue
	else:
		A = []
		for e in edge[i]:
			if e == Par[i]:
				A.append(n - 1 - C[i])
			else:
				A.append(C[e] + 1)
		cur = 1 + (len(edge[i]) - 1) * H[-1]
		for a in A:
			cur -= H[n - 1 - a]
		ans = (ans + cur) % mod
print(ans * H[1] % mod)


import sys
sys.setrecursionlimit(2147483647)
INF = float('inf')
MOD = 10 ** 9 + 7
input = lambda : sys.stdin.readline().rstrip()

def resolve():
	n = int(input())
	E = [[] for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		u -= 1
		v -= 1
		E[u].append(v)
		E[v].append(u)
	size = [1] * n
	stack = [(0, -1)]
	while stack:
		(v, p) = stack.pop()
		if v >= 0:
			for nv in E[v]:
				if nv == p:
					continue
				stack.append((~nv, v))
				stack.append((nv, v))
		else:
			size[p] += size[~v]

	def rerooting(v, p):
		if p == -1:
			return
		size[p] -= size[v]
		size[v] += size[p]
	res = [None] * n
	stack = [(0, -1)]
	while stack:
		(v, p) = stack.pop()
		if v >= 0:
			rerooting(v, p)
			if res[v] is None:
				cnt = pow(2, n - 1, MOD)
				cnt -= 1
				for nv in E[v]:
					cnt -= pow(2, size[nv], MOD) - 1
				res[v] = cnt % MOD
			for nv in E[v]:
				if nv == p:
					continue
				stack.append((~nv, v))
				stack.append((nv, v))
		else:
			rerooting(p, ~v)
	print(sum(res) * pow(2, n * (MOD - 2) % (MOD - 1), MOD) % MOD)
resolve()


import sys
sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
n = int(input())
g = [[] for _ in range(n)]
for i in range(n - 1):
	(a, b) = [int(i) for i in readline().split()]
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)
cnt = [-1] * n
parent = [-1] * n
q = [0]
order = []
while q:
	v = q.pop()
	order.append(v)
	for c in g[v]:
		if parent[v] != c:
			parent[c] = v
			q.append(c)
MOD = 10 ** 9 + 7
pow2 = [1]
for i in range(n):
	pow2.append(pow2[-1] * 2 % MOD)
num = [0] * n
ans = 0
for v in reversed(order):
	res = 1
	nokori = n - 1
	for c in g[v]:
		if c != parent[v]:
			nc = num[c] + 1
			res += pow2[nc] - 1
			num[v] += nc
			nokori -= nc
	res += pow2[nokori] - 1
	ans += pow2[n - 1] - res
R = (MOD + 1) // 2
print(ans * pow(R, n, MOD) % MOD)


import sys
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7
p2 = [1] * (3 * 10 ** 5)
for n in range(3 * 10 ** 5 - 1):
	p2[n + 1] = p2[n] * 2 % mod
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N - 1)]
g = [[] for _ in range(N + 1)]
for i in range(N - 1):
	(a, b) = AB[i]
	g[a].append(b)
	g[b].append(a)
l1 = [0] * (N + 1)
l2 = [[] for _ in range(N + 1)]

def rec(p, c):
	res = 0
	for a in g[c]:
		if a == p:
			continue
		n = rec(c, a)
		l2[c].append(n + 1)
		res += n + 1
	l1[c] = res
	return res
n = rec(0, 1)
for i in range(1, N + 1):
	l2[i].append(N - 1 - l1[i])
ans = 0
for i in range(1, N + 1):
	ans += p2[N - 1] - 1
	ans %= mod
	for j in l2[i]:
		ans -= p2[j] - 1
		ans %= mod
ans *= pow(p2[N], mod - 2, mod)
ans %= mod
print(ans)


import sys, heapq
input = sys.stdin.readline

def main():
	mod = 10 ** 9 + 7
	n = int(input())
	edge = [[] for _ in [0] * n]
	for i in range(n - 1):
		(a, b) = map(int, input().split())
		edge[a - 1].append(b - 1)
		edge[b - 1].append(a - 1)
	p = -1
	ma = -1
	for i in range(n):
		if len(edge[i]) > ma:
			p = i
			ma = len(edge[i])
	par = [-2] * n
	par[p] = -1
	order = []
	tank = [p]
	while tank:
		x = tank.pop()
		order.append(x)
		for elt in edge[x]:
			if par[elt] == -2:
				par[elt] = x
				tank.append(elt)
	size = [1] * n
	for i in range(n - 1, 0, -1):
		now = order[i]
		size[par[now]] += size[now]
	se_N1 = pow(2, n - 1, mod)
	res = 0
	for i in range(n):
		if size[i] == 1:
			continue
		Q = []
		for elt in edge[i]:
			if elt == par[i]:
				Q.append(n - size[i])
			else:
				Q.append(size[elt])
		res = (res + se_N1) % mod
		cpm = 1
		for e in Q:
			cpm = (cpm + pow(2, e, mod) - 1) % mod
		res = (res - cpm) % mod
	print(res * pow(2, n * (mod - 2), mod) % mod)
main()


import sys
input = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
N = int(input())
adj = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(a, b) = map(int, input().split())
	adj[a].append(b)
	adj[b].append(a)
st = [1]
seen = [0] * (N + 1)
seen[1] = 1
child = [[] for _ in range(N + 1)]
seq = []
while st:
	v = st.pop()
	seq.append(v)
	for u in adj[v]:
		if not seen[u]:
			seen[u] = 1
			st.append(u)
			child[v].append(u)
seq.reverse()
ans = 0
half = pow(2, mod - 2, mod)
half_n = pow(half, N - 1, mod)
dp = [1] * (N + 1)
for v in seq:
	tmp = (1 - half_n) % mod
	tmp2 = 0
	for u in child[v]:
		dp[v] += dp[u]
		tmp2 = (tmp2 + (1 - pow(half, dp[u], mod)) % mod * pow(half, N - dp[u] - 1, mod) % mod) % mod
	if dp[v] < N:
		tmp2 = (tmp2 + (1 - pow(half, N - dp[v], mod)) % mod * pow(half, dp[v] - 1, mod) % mod) % mod
	if child[v]:
		tmp = (tmp - tmp2) % mod
		ans = (ans + tmp) % mod
print(ans * half % mod)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
m = map(int, read().split())
AB = zip(m, m)
MOD = 10 ** 9 + 7
graph = [[] for _ in range(N + 1)]
for (a, b) in AB:
	graph[a].append(b)
	graph[b].append(a)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
	x = stack.pop()
	order.append(x)
	for y in graph[x]:
		if y == parent[x]:
			continue
		parent[y] = x
		stack.append(y)
x = (MOD + 1) // 2
power = [1] * (N + 100)
power_inv = [1] * (N + 100)
for i in range(1, N + 100):
	power[i] = power[i - 1] * 2 % MOD
	power_inv[i] = power_inv[i - 1] * x % MOD
answer = 0
size = [1] * (N + 1)
p_size = [N - 1] * (N + 1)
prod = [1] * (N + 1)
coef = [1] * (N + 1)
for v in order[::-1]:
	p = parent[v]
	x = size[v]
	size[p] += x
	prod[p] *= power_inv[x]
	prod[p] %= MOD
	coef[p] += power[x] - 1
	x = N - x
	prod[v] *= power_inv[x]
	coef[v] += power[x] - 1
	E = 1 - prod[v] * coef[v] % MOD
	answer += E
answer *= power_inv[1]
answer %= MOD
print(answer)


import sys
input = sys.stdin.readline
import math
from collections import deque
from fractions import gcd
from functools import lru_cache
MOD = 10 ** 9 + 7
INF = float('inf')

def inputI():
	return int(input().strip())

def inputS():
	return input().strip()

def inputIL():
	return list(map(int, input().split()))

def inputSL():
	return list(map(str, input().split()))

def inputILs(n):
	return list((int(input()) for _ in range(n)))

def inputSLs(n):
	return list((input().strip() for _ in range(n)))

def inputILL(n):
	return [list(map(int, input().split())) for _ in range(n)]

def inputSLL(n):
	return [list(map(str, input().split())) for _ in range(n)]

def inv(n):
	return pow(n, MOD - 2, MOD)
kaijo_memo = []

def kaijo(n):
	if len(kaijo_memo) > n:
		return kaijo_memo[n]
	if len(kaijo_memo) == 0:
		kaijo_memo.append(1)
	while len(kaijo_memo) <= n:
		kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
	return kaijo_memo[n]
gyaku_kaijo_memo = []

def gyaku_kaijo(n):
	if len(gyaku_kaijo_memo) > n:
		return gyaku_kaijo_memo[n]
	if len(gyaku_kaijo_memo) == 0:
		gyaku_kaijo_memo.append(1)
	while len(gyaku_kaijo_memo) <= n:
		gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD)
	return gyaku_kaijo_memo[n]

def nCr(n, r):
	if n == r:
		return 1
	if n < r or r < 0:
		return 0
	ret = 1
	ret = ret * kaijo(n) % MOD
	ret = ret * gyaku_kaijo(r) % MOD
	ret = ret * gyaku_kaijo(n - r) % MOD
	return ret

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
		if temp % i == 0:
			cnt = 0
			while temp % i == 0:
				cnt += 1
				temp //= i
			arr.append([i, cnt])
	if temp != 1:
		arr.append([temp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr

def lcm(a, b):
	return a * b // gcd(a, b)
N = inputI()
l = inputILL(N - 1)
dic = dict([(i, []) for i in range(1, N + 1)])
for i in l:
	dic[i[0]].append(i[1])
	dic[i[1]].append(i[0])
d = [[INF, i] for i in range(N + 1)]
d[1][0] = 0
q = deque([1])
while q:
	x = q.popleft()
	nd = d[x][0] + 1
	for nx in dic[x]:
		if nd < d[nx][0]:
			d[nx][0] = nd
			q.append(nx)
d_ = sorted(d[1:], reverse=True)
n = [1 for _ in range(N + 1)]
for item in d_:
	depth = item[0]
	i = item[1]
	for j in dic[i]:
		if d[j][0] == depth + 1:
			n[i] += n[j]
ans = (pow(2, N, MOD) - N * pow(2, N - 1, MOD) - 1) % MOD
for i in range(2, N + 1):
	ans = (ans + (pow(2, n[i], MOD) - 1) * (pow(2, N - n[i], MOD) - 1)) % MOD
print(ans * inv(pow(2, N, MOD)) % MOD)


import sys
readline = sys.stdin.buffer.readline
N = int(readline())
graph = [[] for _ in range(N + 1)]
for i in range(N - 1):
	(a, b) = map(int, readline().split())
	lb = 1 << i
	graph[a].append(b)
	graph[b].append(a)
root = 1
parent = [0] * (N + 1)
order = []
stack = [root]
while stack:
	x = stack.pop()
	order.append(x)
	for y in graph[x]:
		if y == parent[x]:
			continue
		parent[y] = x
		stack.append(y)
MOD = 10 ** 9 + 7
x = (MOD + 1) // 2
power_inv = [1] * (N + 100)
for i in range(1, N + 100):
	power_inv[i] = power_inv[i - 1] * x % MOD
size = [1] * (N + 1)
p_size = [N - 1] * (N + 1)
prod = [1] * (N + 1)
coef = [1] * (N + 1)
for v in order[::-1]:
	p = parent[v]
	x = size[v]
	size[p] += x
ans = 0
for i in size[2:]:
	ans += 1 - power_inv[i] - power_inv[N - i] + power_inv[N]
	ans %= MOD
ans = ans - N * power_inv[1] + 1 - power_inv[N]
ans %= MOD
print(ans)


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7
N = int(input())
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(x, y) = map(int, input().split())
	edge[x].append(y)
	edge[y].append(x)
ans = 0
pow2 = [1] * (N + 1)
for i in range(1, N + 1):
	pow2[i] = pow2[i - 1] * 2 % mod

def dfs(s, p=-1):
	global ans
	res = 1
	tmp = pow2[N - 1] - 1
	for t in edge[s]:
		if t == p:
			continue
		size = dfs(t, s)
		res += size
		tmp = (tmp - pow2[size] + 1 + mod) % mod
	if N != res:
		tmp = (tmp - pow2[N - res] + 1 + mod) % mod
	ans = (ans + tmp) % mod
	return res
dfs(1)
div = pow2[N]
print(ans * pow(div, mod - 2, mod) % mod)


from collections import defaultdict, deque
import sys
import math

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())
mod = 1000000007

def solve():
	n = I()
	v = [[] for i in range(n)]
	for i in range(n - 1):
		(a, b) = LI()
		a -= 1
		b -= 1
		v[a].append(b)
		v[b].append(a)
	q = deque([0])
	d = [0] * n
	d[0] = 1
	pre = [None] * n
	while q:
		x = q.popleft()
		nd = d[x] + 1
		for y in v[x]:
			if not d[y]:
				d[y] = nd
				pre[y] = x
				q.append(y)
	V = list(range(1, n))
	V.sort(key=lambda x: -d[x])
	size = [1] * n
	for i in V:
		size[pre[i]] += size[i]
	inv = pow(2, mod - 2, mod)
	ans = (1 - pow(inv, n, mod) - n * inv) % mod
	p = [pow(inv, i, mod) for i in range(n)]
	for i in range(1, n):
		a = size[i]
		b = n - a
		ans += (p[a] - 1) * (p[b] - 1) % mod
		ans %= mod
	print(ans)
	return
solve()


import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
MOD = 10 ** 9 + 7
n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = [int(item) - 1 for item in input().split()]
	edge[a].append(b)
	edge[b].append(a)
childs = [[] for _ in range(n)]

def dfs(p, v):
	val = 1
	for nv in edge[v]:
		if nv == p:
			continue
		ret = dfs(v, nv)
		val += ret
		childs[v].append(ret)
	if val != n:
		childs[v].append(n - val)
	return val
dfs(-1, 0)
total_pattern = pow(2, n, MOD)
total_pattern_inv = pow(total_pattern, MOD - 2, MOD)
inv2 = pow(2, MOD - 2, MOD)
pow2_table = [1]
for i in range(2 * 10 ** 5):
	pow2_table.append(pow2_table[-1] * 2 % MOD)
ans = 0
for line in childs:
	pattern_ok = 0
	if len(line) == 1:
		continue
	for item in line:
		pattern_ok += pow2_table[item] - 1
	pattern_ok += 1
	ans += (total_pattern * inv2 - pattern_ok) * total_pattern_inv
	ans %= MOD
print(ans)


class Tree:
	(C, RL) = ({}, {})
	(R, N, D, S, P) = (None, None, None, None, None)
	SN = None

	def __init__(s, num):
		s.N = num

	def set(s, a, b):
		if a in s.C:
			s.C[a].append(b)
		else:
			s.C[a] = [b]
		if b in s.C:
			s.C[b].append(a)
		else:
			s.C[b] = [a]

	def makeRank(s, root):
		s.R = [0] * s.N
		s.R[root] = 1
		s.RL[1] = [root]
		s.S = [[] for _ in range(s.N)]
		s.P = [-1] * s.N
		F = [root]
		s.D = 2
		while F != []:
			Ft = []
			s.RL[s.D] = []
			for i in F:
				for j in s.C[i]:
					if s.R[j] == 0:
						s.R[j] = s.D
						Ft.append(j)
						s.RL[s.D].append(j)
						s.S[i].append(j)
						s.P[j] = i
			s.D += 1
			F = Ft

	def dfs(s, x):
		t = [-1] * s.N
		S = [x]
		ans = x
		ansn = 0
		t[x] = 0
		while S != []:
			k = S.pop()
			for i in s.C[k]:
				if t[i] == -1:
					t[i] = t[k] + 1
					S.append(i)
					if t[i] > ansn:
						ansn = t[i]
						ans = i
		return (ans, ansn)

	def getDi(s, x=0):
		(a, _) = s.dfs(x)
		(b, ans) = s.dfs(a)
		return ans

	def getDeep(s, x):
		ans = 0
		if x in s.S:
			for i in s.S[x]:
				ans = max(ans, s.getDeep(i))
			return ans + 1
		else:
			return 0

	def getParent(s, x, n):
		if n == 0:
			return x
		if s.P[x] == -1:
			return -n
		return s.getParent(s.P[x], n - 1)

	def countSon(s):
		s.SN = [0] * s.N
		for i in range(s.D - 1, 0, -1):
			for j in s.RL[i]:
				cnt = 1
				for k in s.S[j]:
					cnt += s.SN[k]
				s.SN[j] = cnt

class powmod:
	F = [1, 2]
	Fi = [1, 2]
	I = [0, 1]

	def __init__(self, num, mod):
		self.MOD = mod
		k = 2
		for i in range(2, num + 1):
			self.F.append(self.F[-1] * k % mod)
			self.I.append(mod - self.I[mod % k] * (mod // k) % mod)
			self.Fi.append(self.Fi[-1] * self.I[k] % mod)

class Inv:

	def __init__(s, mod):
		s.MOD = mod

	def modpow(s, a, n):
		res = 1
		while n > 0:
			if n & 1:
				res = res * a % s.MOD
			a = a * a % s.MOD
			n >>= 1
		return res

	def invx(s, a):
		return s.modpow(a, s.MOD - 2)

	def invL(s, a, n):
		ia = s.invx(a)
		L = [1] * (n + 1)
		for i in range(1, n + 1):
			L[i] = L[i - 1] * ia % s.MOD
		return L
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N - 1)]
T = Tree(N)
L = [0] * N
for (a, b) in AB:
	T.set(a - 1, b - 1)
	L[a - 1] += 1
	L[b - 1] += 1
for i in range(N):
	if L[i] == 1:
		root = i
T.makeRank(root)
T.countSon()
MOD = 10 ** 9 + 7
ans = 0
PM = powmod(N, MOD)
I = Inv(MOD)
y = I.invx(PM.F[N])
ans = 0
for i in range(N):
	if i == root:
		continue
	if T.S[i] == []:
		continue
	L = []
	cnt = 0
	for j in T.S[i]:
		L.append(T.SN[j])
		cnt += T.SN[j]
	L.append(N - cnt - 1)
	t = PM.F[N - 1] - 1
	for j in L:
		t = t - PM.F[j] + 1
		if t < 0:
			t += MOD
	ans = (ans + t * y) % MOD
print(ans)


from sys import setrecursionlimit
setrecursionlimit(2 * 10 ** 5)
n = int(input())
ab = [tuple([int(x) - 1 for x in input().split()]) for _ in range(n - 1)]
e = [[] for _ in range(n)]
for (a, b) in ab:
	e[a].append(b)
	e[b].append(a)
MOD = 10 ** 9 + 7
d = []

def modinv(x):
	a = x
	b = MOD
	u = 1
	v = 0
	while b:
		t = a // b
		a -= t * b
		(a, b) = (b, a)
		u -= t * v
		(u, v) = (v, u)
	u %= MOD
	if u < 0:
		u += MOD
	return u

def dfs(x, p):
	if len(e[x]) == 1:
		if e[x][0] == p:
			d.append(1)
			return 1
	ret = 1
	for z in e[x]:
		if z == p:
			continue
		ret += dfs(z, x)
	if x != 0:
		d.append(ret)
	return ret
dfs(0, -1)
f = []
w = 1
for i in range(n + 1):
	f.append(w)
	w = w * 2 % MOD
ans = 0
for x in d:
	ans += (f[x] - 1) * (f[n - x] - 1) % MOD
	ans %= MOD
ans = (ans - f[n - 1] * n + f[n] - 1 + MOD) % MOD
ans = ans * modinv(f[n]) % MOD
print(ans)


class Tree:

	def __init__(self, n, edge, indexed=1):
		self.n = n
		self.tree = [[] for _ in range(n)]
		for e in edge:
			self.tree[e[0] - indexed].append(e[1] - indexed)
			self.tree[e[1] - indexed].append(e[0] - indexed)

	def setroot(self, root):
		self.root = root
		self.parent = [None for _ in range(self.n)]
		self.parent[root] = -1
		self.depth = [None for _ in range(self.n)]
		self.depth[root] = 0
		self.order = []
		self.order.append(root)
		self.size = [1 for _ in range(self.n)]
		stack = [root]
		while stack:
			node = stack.pop()
			for adj in self.tree[node]:
				if self.parent[adj] is None:
					self.parent[adj] = node
					self.depth[adj] = self.depth[node] + 1
					self.order.append(adj)
					stack.append(adj)
		for node in self.order[::-1]:
			for adj in self.tree[node]:
				if self.parent[node] == adj:
					continue
				self.size[node] += self.size[adj]
import sys
input = sys.stdin.readline
MOD = 1000000007
N = int(input())
E = [tuple(map(int, input().split())) for _ in range(N - 1)]
t = Tree(N, E)
t.setroot(0)
res = 0
for node in range(N):
	tmp = pow(2, N - 1, MOD) - 1
	for adj in t.tree[node]:
		if t.parent[node] == adj:
			s = N - t.size[node]
		else:
			s = t.size[adj]
		tmp -= pow(2, s, MOD) - 1
		tmp %= MOD
	res += tmp
	res %= MOD
res *= pow(pow(2, N, MOD), MOD - 2, MOD)
res %= MOD
print(res)


import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
	if y == 0:
		return 1
	elif y == 1:
		return x % mod
	elif y % 2 == 0:
		return power(x, y // 2) ** 2 % mod
	else:
		return power(x, (y - 1) // 2) ** 2 * x % mod

def mul(a, b):
	return a % mod * (b % mod) % mod

def div(a, b):
	return mul(a, power(b, mod - 2))
import sys
input = sys.stdin.readline
N = int(input())
d2 = [1]
inverse = [0, 1]
for _ in range(N):
	d2.append(2 * d2[-1] % mod)
for i in range(2, 10):
	inverse.append(-inverse[mod % i] * (mod // i) % mod)
G = [[] for _ in range(N + 1)]
for v in range(N - 1):
	(a, b) = map(int, input().split())
	G[a].append(b)
	G[b].append(a)
v2i = [0 for _ in range(N + 1)]

def itt(v, p):
	cn = 0
	ms = []
	for u in G[v]:
		if u == p:
			continue
		un = itt(u, v)
		ms.append(un)
		cn += un
	if p != None:
		ms.append(N - 1 - cn)
	v2i[v] = ms
	return cn + 1
itt(1, None)
r = 0
for v in range(1, N + 1):
	ff = v2i[v]
	for f in ff:
		r += d2[f] - 1 % mod
r = N * d2[N - 1] - N - r
for _ in range(N):
	r = r * 500000004 % mod
print(r)


import sys
sys.setrecursionlimit(10 ** 9)
N = int(input())
G = [[] for _ in range(N)]
mod = 10 ** 9 + 7
for _ in range(N - 1):
	(A, B) = map(int, input().split())
	G[A - 1].append(B - 1)
	G[B - 1].append(A - 1)
cnt = [[] for _ in range(N)]
que = [0]
depth = [-1] * N
depth[0] = 0
while que:
	v = que.pop()
	d = depth[v]
	for nv in G[v]:
		if depth[nv] >= 0:
			continue
		depth[nv] = d + 1
		que.append(nv)
d_to_i = [[] for _ in range(N)]
for i in range(N):
	d_to_i[depth[i]].append(i)
for d in range(N)[::-1]:
	for v in d_to_i[d]:
		for nv in G[v]:
			if depth[nv] < depth[v]:
				continue
			if cnt[nv]:
				cnt[v].append(sum(cnt[nv]) + 1)
			else:
				cnt[v].append(1)
for i in range(N):
	res = N - 1
	for j in cnt[i]:
		res -= j
	cnt[i].append(res)
ans = 0
p = [1] * N
for i in range(1, N):
	p[i] = p[i - 1] * 2 % mod
for v in range(N):
	if len(cnt[v]) <= 1:
		continue
	res = p[N - 1] - 1
	for a in cnt[v]:
		res -= p[a] - 1
	ans += res
	ans %= mod
inv = pow(2, (mod - 2) * N, mod)
print(ans * inv % mod)


import sys
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7
n = int(input())
edges = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	edges[a - 1].append((b - 1, i))
	edges[b - 1].append((a - 1, i))
l = [0 for i in range(n)]

def dfs(cur, x):
	res = 1
	for i in edges[cur]:
		if i[1] != x:
			res += dfs(i[0], i[1])
	l[x] = res
	return res
dfs(0, -1)
l2 = [1]
i2 = pow(2, mod - 2, mod)
for i in range(n):
	l2.append(l2[-1] * i2 % mod)
cnt = 0
for i in l:
	cnt += (1 - l2[i]) * (1 - l2[n - i])
print((-n * i2 - l2[-1] + cnt + 1) % mod)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7
N = int(input())
vec = [[] for _ in range(N)]
for _ in range(N - 1):
	(A, B) = map(int, input().split())
	vec[A - 1].append(B - 1)
	vec[B - 1].append(A - 1)
sub_size = [[] for _ in range(N)]

def dfs(cur=0, pre=-1):
	s = 0
	for nex in vec[cur]:
		if nex == pre:
			continue
		t = dfs(nex, cur)
		s += t
		sub_size[cur].append(t)
	if s != N - 1:
		sub_size[cur].append(N - 1 - s)
	return s + 1
dfs()
power = [1]
for _ in range(N):
	power.append(power[-1] * 2 % mod)
ret = 0
for i in range(N):
	tmp = power[N - 1] - 1
	for ss in sub_size[i]:
		tmp -= power[ss] - 1
	ret += tmp
ret = ret * pow(power[N], mod - 2, mod) % mod
print(ret)


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
mod = 10 ** 9 + 7
n = int(input())
g = [[] for _ in range(n)]
pow2 = [0 for _ in range(n + 1)]
pow2[0] = 1
for i in range(n):
	pow2[i + 1] = pow2[i] * 2 % mod
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	g[a - 1].append(b - 1)
	g[b - 1].append(a - 1)

def func(x):
	return pow2[x] - 1

class Tree:

	def __init__(self, crdinal, adjgrph, root, fnction=lambda x: 0):
		self.crdinal = crdinal
		self.adjgrph = adjgrph
		self.root = root
		self.fnction = fnction
		self.parent = [-1] * self.crdinal
		self.depth = [-1] * self.crdinal
		self.subsize = [1] * self.crdinal
		self.result = [0] * self.crdinal
		s = [root]
		while s:
			v = s.pop()
			if self.depth[v] == -1:
				if v == root:
					self.depth[v] = 0
				else:
					self.depth[v] = self.depth[self.parent[v]] + 1
					s.append(v)
				for w in self.adjgrph[v]:
					if self.depth[w] == -1:
						self.parent[w] = v
						s.append(w)
			else:
				self.subsize[self.parent[v]] += self.subsize[v]
				self.result[self.parent[v]] += self.fnction(self.subsize[v])

	def parent(self) -> list:
		return self.parent

	def depth(self) -> list:
		return self.depth

	def size(self) -> list:
		return self.subsize

	def result(self) -> list:
		return self.result
tr = Tree(n, g, 0, func)
sizesub = tr.subsize
black = tr.result
cnt = 0
for i in range(n):
	tmp = pow2[n - 1] - pow2[n - sizesub[i]] - black[i]
	tmp %= mod
	cnt += tmp
	cnt %= mod

def inv(a, mod):
	r = [1, 0, a]
	w = [0, 1, mod]
	while w[2] != 1:
		q = r[2] // w[2]
		r_new = [r[0] - q * w[0], r[1] - q * w[1], r[2] - q * w[2]]
		r = w
		w = r_new
	(x, y) = (w[0], w[1])
	return (mod + x % mod) % mod
print(inv(pow2[n], mod) * cnt % mod)


import sys
sys.setrecursionlimit(505050)
input = sys.stdin.buffer.readline
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N - 1)]
mod = 10 ** 9 + 7
half = mod // 2 + 1
G = [[] for _ in range(N + 1)]
for (a, b) in AB:
	G[a].append(b)
	G[b].append(a)
P = [0] * (N + 1)
Size = [0] * (N + 1)

def dfs(v):
	siz = 1
	p = P[v]
	for u in G[v]:
		if u != p:
			P[u] = v
			dfs(u)
			siz += Size[u]
	Size[v] = siz
dfs(1)
ans = 0
Prob = [0]
h = 1
for i in range(202020):
	h = h * half % mod
	Prob.append(1 - h)
for (v, (siz_v, Gv)) in enumerate(zip(Size[1:], G[1:]), 1):
	if v == 1:
		ps = []
	else:
		ps = [Prob[N - siz_v]]
	par = P[v]
	for u in Gv:
		if par != u:
			siz_u = Size[u]
			ps.append(Prob[siz_u])
	if len(ps) <= 1:
		continue
	cumprod1_ps = [1, 1]
	cumprod2_ps = [1, 1]
	cp = 1
	for p in ps:
		cp = cp * (1 - p) % mod
		cumprod1_ps.append(cp)
	cp = 1
	for p in ps[::-1]:
		cp = cp * (1 - p) % mod
		cumprod2_ps.append(cp)
	cumprod2_ps.reverse()
	an = 1 - cumprod1_ps[-1]
	for (cp1, cp2, p) in zip(cumprod1_ps[1:-1], cumprod2_ps[1:-1], ps):
		an -= cp1 * cp2 % mod * p
	ans += an
ans = ans % mod * half % mod
print(ans)


import sys
import itertools
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7

def my_pow(base, n, mod):
	if n == 0:
		return 1
	x = base
	y = 1
	while n > 1:
		if n % 2 == 0:
			x *= x
			n //= 2
		else:
			y *= x
			n -= 1
		x %= mod
		y %= mod
	return x * y % mod
N = int(input())
adj = [[] for _ in range(N)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	adj[a].append(b)
	adj[b].append(a)
pows = [1] * N
for i in range(1, N):
	pows[i] = pows[i - 1] * 2 % MOD
ans = 0

def dfs(v, p):
	global ans
	subs = []
	res = 1
	for u in adj[v]:
		if u == p:
			continue
		val = dfs(u, v)
		res += val
		subs.append(val)
	if p != -1:
		subs.append(N - res)
	now = pows[N - 1] - 1
	for sub in subs:
		now -= pows[sub] - 1
	ans += now
	ans %= MOD
	return res
dfs(0, -1)
print(ans * my_pow(2 ** N, MOD - 2, MOD) % MOD)


import sys
readline = sys.stdin.readline

class Segtree:

	def __init__(self, A, intv, initialize=True, segf=max):
		self.N = len(A)
		self.N0 = 2 ** (self.N - 1).bit_length()
		self.intv = intv
		self.segf = segf
		if initialize:
			self.data = [intv] * self.N0 + A + [intv] * (self.N0 - self.N)
			for i in range(self.N0 - 1, 0, -1):
				self.data[i] = self.segf(self.data[2 * i], self.data[2 * i + 1])
		else:
			self.data = [intv] * (2 * self.N0)

	def update(self, k, x):
		k += self.N0
		self.data[k] = x
		while k > 0:
			k = k >> 1
			self.data[k] = self.segf(self.data[2 * k], self.data[2 * k + 1])

	def query(self, l, r):
		(L, R) = (l + self.N0, r + self.N0)
		s = self.intv
		while L < R:
			if R & 1:
				R -= 1
				s = self.segf(s, self.data[R])
			if L & 1:
				s = self.segf(s, self.data[L])
				L += 1
			L >>= 1
			R >>= 1
		return s

	def binsearch(self, l, r, check, reverse=False):
		(L, R) = (l + self.N0, r + self.N0)
		(SL, SR) = ([], [])
		while L < R:
			if R & 1:
				R -= 1
				SR.append(R)
			if L & 1:
				SL.append(L)
				L += 1
			L >>= 1
			R >>= 1
		if reverse:
			for idx in SR + SL[::-1]:
				if check(self.data[idx]):
					break
			else:
				return -1
			while idx < self.N0:
				if check(self.data[2 * idx + 1]):
					idx = 2 * idx + 1
				else:
					idx = 2 * idx
			return idx - self.N0
		else:
			for idx in SL + SR[::-1]:
				if check(self.data[idx]):
					break
			else:
				return -1
			while idx < self.N0:
				if check(self.data[2 * idx]):
					idx = 2 * idx
				else:
					idx = 2 * idx + 1
			return idx - self.N0

def parorder(Edge, p):
	N = len(Edge)
	par = [0] * N
	par[p] = -1
	stack = [p]
	order = []
	visited = set([p])
	ast = stack.append
	apo = order.append
	while stack:
		vn = stack.pop()
		apo(vn)
		for vf in Edge[vn]:
			if vf in visited:
				continue
			visited.add(vf)
			par[vf] = vn
			ast(vf)
	return (par, order)

def getcld(p):
	res = [[] for _ in range(len(p))]
	for (i, v) in enumerate(p[1:], 1):
		res[v].append(i)
	return res
N = int(readline())
MOD = 10 ** 9 + 7
Edge = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, readline().split())
	a -= 1
	b -= 1
	Edge[a].append(b)
	Edge[b].append(a)
pow2 = [1] * (N + 3)
for i in range(1, len(pow2)):
	pow2[i] = 2 * pow2[i - 1] % MOD
(P, L) = parorder(Edge, 0)
dp1 = [0] * N
dp2 = [0] * N
size = [1] * N
for l in L[:0:-1]:
	p = P[l]
	size[p] += size[l]
for l in L[:0:-1]:
	p = P[l]
	dp1[l] = (dp1[l] + pow2[size[l] - 1] - 1) % MOD
	dp2[l] = (dp2[l] + pow2[size[l] - 1] - 1) % MOD
	k = pow2[size[p] - 1 - size[l]]
	dp1[p] = (dp1[p] - (pow2[size[l]] - 1) + (2 * k - 1) * dp2[l] + dp1[l]) % MOD
	dp2[p] = (dp2[p] + 2 * dp2[l] * k) % MOD
dp1[0] = (dp1[0] + pow2[size[0] - 1] - 1) % MOD
print(dp1[0] * pow(pow(2, N, MOD), MOD - 2, MOD) % MOD)


import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60

def main():
	MOD = 1000000007
	(N, *AB) = list(map(int, read().split()))
	G = [[] for _ in range(N)]
	for (a, b) in zip(AB[::2], AB[1::2]):
		G[a - 1].append(b - 1)
		G[b - 1].append(a - 1)
	stack = deque([0])
	order = []
	prev = [0] * N
	prev[0] = -1
	while stack:
		v = stack.pop()
		order.append(v)
		for nv in G[v]:
			if nv != prev[v]:
				stack.append(nv)
				prev[nv] = v
	pow2 = [0] * (N + 1)
	pow2[0] = 1
	for i in range(N):
		pow2[i + 1] = pow2[i] * 2 % MOD
	nodes = [1] * N
	numer = 0
	for v in reversed(order):
		if prev[v] != -1:
			nodes[prev[v]] += nodes[v]
		numer = (numer + pow2[N - 1] - 1 - (pow2[N - nodes[v]] - 1)) % MOD
		for nv in G[v]:
			if nv != prev[v]:
				numer = (numer - (pow2[nodes[nv]] - 1)) % MOD
	denom = pow2[N]
	ans = numer * pow(denom, MOD - 2, MOD) % MOD
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7
e = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(u, v) = map(int, input().split())
	e[u].append(v)
	e[v].append(u)
s = [1]
order = []
parent = [0] * (N + 1)
size = [1] * (N + 1)
vis = [0] * (N + 1)
while len(s):
	x = s.pop()
	order.append(x)
	vis[x] = 1
	for y in e[x]:
		if vis[y]:
			continue
		s.append(y)
		vis[y] = 1
		parent[y] = x
order.reverse()
for y in order[:-1]:
	size[parent[y]] += size[y]
rev = lambda x: pow(x, mod - 2, mod)
res = rev(2) - rev(pow(2, N, mod))
res %= mod
for y in e[1]:
	res -= rev(pow(2, N - size[y], mod)) * (1 - rev(pow(2, size[y], mod)))
	res %= mod
order.reverse()
for y in order[1:]:
	t = rev(2) - rev(pow(2, N, mod))
	x = parent[y]
	for z in e[y]:
		if x == z:
			continue
		t -= rev(pow(2, N - size[z], mod)) * (1 - rev(pow(2, size[z], mod)))
		t %= mod
	t -= rev(pow(2, size[y], mod)) * (1 - rev(pow(2, N - size[y], mod)))
	t %= mod
	res += t
	res %= mod
print(res)


from collections import deque
from heapq import heappop, heappush
N = int(input())
MOD = 10 ** 9 + 7
L = [[] for i in range(N + 1)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	L[a].append(b)
	L[b].append(a)
parent = [0] * (N + 1)
order = []
stack = [1]
while stack:
	x = stack.pop()
	order.append(x)
	for y in L[x]:
		if y == parent[x]:
			continue
		parent[y] = x
		stack.append(y)
half = pow(2, MOD - 2, MOD)
power_inv = [1] * (N + 1)
size = [1] * (N + 1)
for (i, v) in enumerate(order[::-1], 1):
	p = parent[v]
	x = size[v]
	size[p] += x
	power_inv[i] = power_inv[i - 1] * half % MOD
ans = sum(((1 - power_inv[i] - power_inv[N - i] + power_inv[N]) % MOD for i in size[2:]))
ans += 1
ans -= power_inv[N] + N * power_inv[1]
ans %= MOD
print(ans)


import sys
import heapq as h
input = sys.stdin.readline
N = int(input())
hen = [[] for i in range(0, N)]
for i in range(0, N - 1):
	(a, b) = map(int, input().split())
	hen[a - 1].append(b - 1)
	hen[b - 1].append(a - 1)
mod = 10 ** 9 + 7
subtreesize = [1 for i in range(0, N)]
flag = [0 for i in range(0, N)]
q = []
for i in range(1, N):
	if len(hen[i]) == 1:
		q.append(i)
		flag[i] = 0
h.heapify(q)
sub = []
h.heapify(sub)
while q != []:
	while q != []:
		x = h.heappop(q)
		for p in hen[x]:
			if p != 0:
				if flag[p] != len(hen[p]) - 1:
					subtreesize[p] += subtreesize[x]
					flag[p] += 1
					if flag[p] == len(hen[p]) - 1:
						h.heappush(sub, p)
			else:
				subtreesize[p] += subtreesize[x]
		if q == []:
			q = sub
			sub = []
			h.heapify(sub)
			break
ans = [0 for i in range(0, N)]
flag = [0 for i in range(0, N)]
q = []
for i in range(1, N):
	if len(hen[i]) == 1:
		q.append(i)
		flag[i] = 0
h.heapify(q)
sub = []
h.heapify(sub)
while q != []:
	while q != []:
		x = h.heappop(q)
		for p in hen[x]:
			if p != 0:
				if flag[p] != len(hen[p]) - 1:
					ans[p] = (ans[p] + ans[x] - pow(2, subtreesize[x], mod) + 1) % mod
					flag[p] += 1
					if flag[p] == len(hen[p]) - 1:
						ans[p] = (ans[p] + pow(2, N - 1, mod) - pow(2, N - subtreesize[p], mod)) % mod
						h.heappush(sub, p)
			else:
				ans[p] = (ans[p] + ans[x] - pow(2, subtreesize[x], mod) + 1) % mod
		if q == []:
			q = sub
			sub = []
			h.heapify(sub)
			break
ans[0] = (ans[0] + pow(2, N - 1, mod) - 1) % mod
print(ans[0] * pow(2, N * (mod - 2), mod) % mod)