# 计蒜客 Random Access Iterator

 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #define MOD 1000000007 #define ll long long using namespace std; int n; int MDep; vector edges[1000005]; bool visited[1000005]; ll quickpow(ll a, ll b) {     if (b == 0)return 1;     ll re = quickpow(a, b / 2) % MOD;     re = (re * re) % MOD;     if (b % 2 == 1)re *= a % MOD;     return re % MOD; } inline ll inv(ll x) {     return quickpow(x, MOD - 2) % MOD; } inline ll chance1(ll TotNode) {     ll ch = (inv(TotNode)) % MOD;     return ch; } inline ll chance2(ll onceCh,ll TotNode) {     ll onceNonch = (1ll-onceCh+MOD) % MOD;     ll nonch = quickpow(onceNonch, TotNode);     ll fin = (1ll - nonch + MOD) % MOD;     return fin; } int dfsMaxDep(int node) {     int maxDep = 1;     bool hasChild = false;     visited[node] = true;     for (int i = 0; i < edges[node].size(); i++) {         if (visited[edges[node][i]])continue;         hasChild = true;         maxDep = max(maxDep, dfsMaxDep(edges[node][i]) + 1);     }     return maxDep; } ll dfsChance(int depth,int node){     if (depth == MDep)return 1;     ll ch = 0,sCh=chance1(node==1?edges[node].size(): edges[node].size()-1);     visited[node] = true;     for (int i = 0; i < edges[node].size(); i++) {         if (visited[edges[node][i]])continue;         ll CurCH = dfsChance(depth + 1, edges[node][i]);         if (CurCH) {             ch += (CurCH * sCh) % MOD;             ch %= MOD;         }     }     return chance2(ch, node == 1 ? edges[node].size() : edges[node].size() - 1); } int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {         int u, v;         cin >> u >> v;         edges[u].push_back(v);         edges[v].push_back(u);     }     MDep = dfsMaxDep(1);     memset(visited, false, sizeof(visited));     ll ch = dfsChance(1, 1);     cout << ch; }