#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; int N; vector> G; ll ans = 0; vector dist(N); int dfs(int v) { int cnt = 1; for (int e:G[v]) { dist[e] = dist[v] + 1; cnt += dfs(e); } ans += cnt*dist[v]; ans %= MOD; return cnt; } int main(){ cin >> N; G.resize(N); dist.resize(N); fill(dist.begin(),dist.end(),-1); vector deg(N,0); rep(i,N - 1) { int a,b; cin >> a >> b; --a; --b; G[a].push_back(b); deg[b] ++; } int root; rep(i,N) { if (deg[i] == 0) { root = i; break; } } dist[root] = 0; dfs(root); cout << ans << endl; return 0; }