#include #include #include #include #include using mint = atcoder::modint998244353; int edge_num(int n) { return (n * (n + 1)) >> 1; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n; std::vector> g(n); for (int i = 0; i < n - 1; ++i) { int u, v; std::cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); } const int m = edge_num(n); const mint inv_m = mint(m).inv(); struct SubtreeSize { SubtreeSize(int n, const std::vector> &g) : _n(n), _par(_n, -1), _siz(_n, 1) { auto dfs = [&](auto dfs, int u, int p) -> int { _par[u] = p; for (int v : g[u]) if (v != p) { _siz[u] += dfs(dfs, v, u); } return _siz[u]; }; dfs(dfs, 0, -1); } int operator()(int u, int p) const { return _par[u] == p ? _siz[u] : _n - _siz[p]; } int t(int u, int ng1) const { return _n - (*this)(ng1, u); } int t(int u, int ng1, int ng2) const { return _n - (*this)(ng1, u) - (*this)(ng2, u); } private: int _n; std::vector _par, _siz; } subtree_size { n, g }; std::vector ans_f(n, 0); for (int x = 0; x < n; ++x) { int u_x = edge_num(n); for (int y : g[x]) { u_x -= edge_num(subtree_size(y, x)); } ans_f[x] = m * mint(m - u_x).inv(); } std::vector> ans_g(n, std::vector(n)); std::vector> par(n, std::vector(n, -1)); // x, y, A, B std::deque> dq; for (int x = 0; x < n; ++x) { ans_g[x][x] = ans_f[x]; int u_x = edge_num(n); for (int y : g[x]) { const int s_y = subtree_size(y, x); u_x -= edge_num(s_y); } for (int y : g[x]) { const int s_y = subtree_size(y, x); par[x][y] = x; const int u_y = u_x - s_y * (n - s_y); const mint A = u_y * ans_f[x]; const mint B = 0; dq.emplace_back(x, y, A, B); } } while (dq.size()) { auto [x, z, A, B] = dq.front(); dq.pop_front(); const int par_z = par[x][z]; const int s_z = subtree_size(z, par_z); int u_z = edge_num(s_z); for (int y : g[z]) if (y != par_z) { u_z -= edge_num(subtree_size(y, z)); } const int t_z = s_z; ans_g[x][z] = A + u_z * ans_f[z] + B; int prev_z2 = z, z2 = par_z; while (z2 != x) { const int next_z2 = par[x][z2]; const int t_z2 = subtree_size.t(z2, prev_z2, next_z2); ans_g[x][z] += t_z * t_z2 * ans_g[z][z2]; std::tie(prev_z2, z2) = std::make_tuple(z2, next_z2); } const int t_x = subtree_size.t(x, prev_z2); ans_g[x][z] = (1 + ans_g[x][z] * inv_m) * (1 - t_x * t_z * inv_m).inv(); for (int y : g[z]) if (y != par_z) { const int s_y = subtree_size(y, z); const int next_t_z = t_z - s_y; const int u_y = u_z - s_y * (s_z - s_y); const mint next_A = A + u_y * ans_f[z]; mint next_B = B + next_t_z * t_x * ans_g[x][z]; int prev_z2 = z, z2 = par_z; while (z2 != x) { const int next_z2 = par[x][z2]; const int t_z2 = subtree_size.t(z2, prev_z2, next_z2); next_B += next_t_z * t_z2 * ans_g[z][z2]; std::tie(prev_z2, z2) = std::make_tuple(z2, next_z2); } par[x][y] = z; dq.emplace_back(x, y, next_A, next_B); } } mint ans = 1; for (int x = 0; x < n; ++x) { for (int y = 0; y <= x; ++y) { ans += ans_g[x][y] * inv_m; } } std::cout << ans.val() << '\n'; return 0; }