#include #include #include #include #include #include #include #include #include #include #include #include typedef unsigned long long ULLONG; typedef long long LLONG; static const LLONG MOD_NUM = 1000000007;//998244353; template static void getval(_T& a) { std::cin >> a; } template static void getval(_T& a, _T& b) { std::cin >> a >> b; } template static void getval(_T& a, _T& b, _T& c) { std::cin >> a >> b >> c; } static void exec(); int main() { exec(); fflush(stdout); return 0; } static LLONG dfs(std::vector>& graph, int here, int pass) { LLONG ans = 0; for (auto it = graph[here].begin(); it != graph[here].end(); it++) { ans = (ans + dfs(graph, *it, pass + 1)) % MOD_NUM; } ans += (pass * (pass + 1) / 2LL) % MOD_NUM; ans %= MOD_NUM; return ans; } static void exec() { int N; getval(N); std::set vers; for (int i = 0; i < N; i++) { vers.insert(i); } std::vector> graph(N); for (int i = 1; i < N; i++) { int a, b; getval(a, b); a--; b--; graph[a].push_back(b); vers.erase(b); } printf("%lld\n", dfs(graph, *(vers.begin()), 0)); }