MOD = 10**9 + 7 n = read_line.to_i g = Array.new(n) { [] of Int32 } flag = [false] * n n.pred.times do a, b = read_line.split.map &.to_i.pred g[a] << b flag[b] = true end def dfs(v, dist, g) res = (1i64..dist.to_i64).sum g[v].each do |u| res += dfs(u, dist + 1, g) end res % MOD end puts dfs(flag.index(false).not_nil!, 0, g)