#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 220000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
#define graph_from1 true
#define graph_tree true
#define graph_weight false
#define graph_digraph false

class Graph_func {
public:
	int Vnum;
	int Enum;
	vector<pii> edgelist;
	vl edgeweight;
	vector<vi> adjlist;
	vector<vl> adjlistweight;
	vi adjnum;

	vi adj_to_root;
	vector<int> DP;
	vi vlist_from_root;
	vl xdist;
	
	vb x_visited;
	vi x_prqarr;
	vb x_filled;

	void read_edge();
	void adjini();
	void visited_ini();
	void adjsort();
	vb graph_num_BFS(int BFS_ini, vb filled);
	int graph_num();
	void graph_BFS(ll BFS_ini);
	void graph_DFS(ll DFS_ini);
	void xydist_tree(int x);   // ex. xydist_tree(3)
	void xydist(int x);   // ex. xydist(3, 0)
	ll diameter();
	void ReRooting(ll root);
	int dim_num(int dim);
	void solve();

	bool xydist_def = false;
};

void Graph_func::read_edge() {
	cin >> Vnum;
	if (graph_tree)
		Enum = Vnum - 1;// graph
	else
		cin >> Enum;
	edgelist.resize(Enum);
	edgeweight.resize(Enum);
	adjnum.resize(Vnum);
	xdist.resize(Vnum);
	adjlist.resize(Vnum);
	if(graph_weight)
		adjlistweight.resize(Vnum);
	adj_to_root.resize(Vnum, -1);
	DP.resize(Vnum, 0);
	rep(i, Enum) {
		if (graph_weight)
			cin >> edgelist[i].first >> edgelist[i].second >> edgeweight[i];
		else
			cin >> edgelist[i].first >> edgelist[i].second;
		if (graph_from1) {
			edgelist[i].first--;
			edgelist[i].second--;
		}
	}
	return;
}

void Graph_func::adjini() {
	rep(i, Vnum)
		adjnum[i] = 0;
	rep(i, Enum) {
		int x = edgelist[i].first;
		int y = edgelist[i].second;
		adjlist[x].push_back(y);
		if(!graph_digraph)
			adjlist[y].push_back(x);
		if (graph_weight) {
			ll xyweight = edgeweight[i];
			adjlistweight[x].push_back(xyweight);
			if (!graph_digraph)
				adjlistweight[y].push_back(xyweight);
		}
		adjnum[x]++;
		if (!graph_digraph)
			adjnum[y]++;
	}
	x_visited.resize(Vnum);
	visited_ini();

	return;
}

void Graph_func::visited_ini() {
	rep(i, Vnum)
		x_visited[i] = false;
	x_prqarr.resize(0);
}

void Graph_func::adjsort() {
	rep(i, Vnum)
		sort(adjlist[i].begin(), adjlist[i].end(), less<int>());
	return;
}

vb Graph_func::graph_num_BFS(int BFS_ini, vb filled) { // ex. graph_num_BFS(i, filled);
	x_prqarr.push_back(BFS_ini);
	x_visited[BFS_ini] = true;

	while (!x_prqarr.empty())	{
		int Ntmp = x_prqarr.size();
		vi x_prqarr_next(0);
		rep(n, Ntmp) {
			int x = x_prqarr[n];
			rep(i, adjnum[x]) {
				int x_new = adjlist[x][i];
				if (!x_visited[x_new]) {
					x_prqarr_next.push_back(x_new);
					x_visited[x_new] = true;
					filled[x_new] = true;
				}
			}
		}
		x_prqarr = x_prqarr_next;
	}
	return filled;
}

int Graph_func::graph_num() {
	int anstmp = 0;
	int i = 0;
	vector<bool> filled;
	filled.resize(Vnum);
	rep(j, Vnum)
		filled[j] = false;
	bool end = false;
	while (!end)	{
		if (i >= Vnum)
			break;
		while (1) {
			if (!filled[i])
				break;
			i++;
			if (i >= Vnum) {
				end = true;
				break;
			}
		}
		if (end)
			break;
		filled[i] = true;
		filled = graph_num_BFS(i, filled);
		anstmp++;
	}
	return anstmp;
}

void Graph_func::graph_BFS(ll BFS_ini) {
	visited_ini();
	x_prqarr.push_back(BFS_ini);
	x_visited[BFS_ini] = true;
	vlist_from_root.resize(1, BFS_ini);
	while (!x_prqarr.empty()) {
		vi x_prqarr_next(0);
		int Ntmp = x_prqarr.size();
		rep(n, Ntmp) {
			int x = x_prqarr[n];
			//x_prqarr.erase(x_prqarr.begin());
			rep(i, adjnum[x]) {
				int x_new = adjlist[x][i];
				if (!x_visited[x_new]) {
					adj_to_root[x_new] = x;
					vlist_from_root.push_back(x_new);
					x_prqarr_next.push_back(x_new);
					x_visited[x_new] = true;
					//cout << x_new << endl;
				}
			}
		}
		x_prqarr = x_prqarr_next;
	}
	return;
}

void Graph_func::graph_DFS(ll DFS_ini) {
	visited_ini();
	x_prqarr.push_back(DFS_ini);
	x_visited[DFS_ini] = true;
	
	while (!x_prqarr.empty()) {
		int Ntmp = x_prqarr.size();
		rep(a, Ntmp) {
			int x = x_prqarr[x_prqarr.size() - 1];
			x_prqarr.pop_back();
			rep(i, adjnum[x]) {
				int x_new = adjlist[x][i];
				if (!x_visited[x_new]) {
					adj_to_root[x_new] = x;
					x_prqarr.push_back(x_new);
					x_visited[x_new] = true;
				}
			}
		}
	}
	return;
}

void Graph_func::xydist_tree(int BFS_ini) {  // ex. xydist_tree(3), BFS
	visited_ini();
	x_prqarr.push_back(BFS_ini);
	x_visited[BFS_ini] = true;
	xdist[BFS_ini] = 0;

	while (!x_prqarr.empty()) {
		int Ntmp = x_prqarr.size();
		rep(a, Ntmp) {
			int x = x_prqarr[0];
			x_prqarr.erase(x_prqarr.begin());
			rep(i, adjnum[x]) {
				int x_new = adjlist[x][i];
				int dist_new;
				if (graph_weight)
					dist_new = adjlistweight[x][i];
				else
					dist_new = 1;
				if (!x_visited[x_new]) {
					x_prqarr.push_back(x_new);
					xdist[x_new] = xdist[x] + dist_new;
					x_visited[x_new] = true;
					//cout << x_new << endl;
				}
			}
		}
	}
	return;
}

void Graph_func::xydist(int x) {  // ex. xydist(3), Dijkstra's algorithm
	priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > xdist_que; //Alive_vertices
	ll max_tmp = pow(10, 18) * 4;
	rep(i, Vnum)
		xdist[i] = max_tmp;
	xdist[x] = 0;
	pair<ll, int> xdist_que_tmp;
	xdist_que_tmp.first = 0;
	xdist_que_tmp.second = x;
	xdist_que.push(xdist_que_tmp);
	while (!xdist_que.empty()) {
		xdist_que_tmp = xdist_que.top();
		xdist_que.pop();
		ll xdist_tmp = xdist_que_tmp.first;
		int x_tmp = xdist_que_tmp.second;
		if (xdist[x_tmp] == xdist_tmp) {
			rep(i, adjnum[x_tmp]) {
				int x_new = adjlist[x_tmp][i];
				ll dist_diff;
				if(graph_weight)
					dist_diff = adjlistweight[x_tmp][i];
				else dist_diff = 1;
				if (xdist[x_new] > xdist[x_tmp] + dist_diff) {
					xdist[x_new] = xdist[x_tmp] + dist_diff;
					xdist_que_tmp.first = xdist[x_new];
					xdist_que_tmp.second = x_new;
					xdist_que.push(xdist_que_tmp);
				}
			}
		}
	}
}

ll Graph_func::diameter() {
	ll anstmp = 0;
	if (graph_tree) {
		ll anstmp_i = 0;
		pii longest;
		xydist_tree(0);
		rep(i, Vnum) {
			if (xdist[i] > anstmp) {
				anstmp = xdist[i];
				anstmp_i = i;
			}
		}
		longest.first = anstmp_i;
		anstmp = 0, anstmp_i = 0;
		xydist_tree(longest.first);
		rep(i, Vnum) {
			if (xdist[i] > anstmp) {
				anstmp = xdist[i];
				anstmp_i = i;
			}
		}
		longest.second = anstmp_i;
	}
	else {
		rep(i, Vnum) {
			xydist(i);
			rep(j, Vnum) {
				anstmp = max(anstmp, xdist[j]);
			}
		}
	}
	return anstmp;
}


void Graph_func::ReRooting(ll root) {
	rep(i, Vnum) {
		DP[i] = 1;
	}
	graph_BFS(root);
	for (int i = Vnum - 1; i >= 0; i--) { // 根から遠い点から見る
		ll x = vlist_from_root[i];
		rep(j, adjnum[x]) {
			ll x_new = adjlist[x][j];
			if (x_new == adj_to_root[x]) // 根側
				continue;
			DP[x] += DP[x_new];
		}
	}
	return;
}


int Graph_func::dim_num(int dim) {
	int anstmp = 0;
	rep(i, Vnum) {
		if (adjnum[i] == dim)
			anstmp++;
	}
	return anstmp;
}

vl pow2;
void pow2_ini() {
	pow2.push_back(1);
	rep(i, nmax_def) {
		ll pow2_next = pow2[i] * 2;
		pow2_next %= mod;
		pow2.push_back(pow2_next);
	}
	return;
}

void Graph_func::solve() {
	pow2_ini();
	ll x = pow2[Vnum];
	ll y = 0;
	rep(i, Vnum) {
		int Vnum1 = DP[i];
		int Vnum2 = Vnum - DP[i];
		ll ytmp = (pow2[Vnum1] - 1) * (pow2[Vnum2] - 1);
		ytmp %= mod;
		y += ytmp;
		y %= mod;
	}
	y += pow2[Vnum]; // 基本的に(辺の数 + 1)==(頂点の数)
	y--; // 全て白のとき(辺の数)==(頂点の数)==0
	y -= pow2[Vnum - 1] * (ll)Vnum;
	y += mod * (ll)Vnum;
	y %= mod;
	ll z = 0;
	while (1) {
		if ((x * z - y + mod) % mod == 0) {
			break;
		}
		z++;
	}
	cout << z << endl;
}

int main(void) {
	Graph_func graph;
	graph.read_edge();
	graph.adjini();
	graph.ReRooting(0);
	graph.solve();
	return 0;
}

Measured memory_bytes: 22420