1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| #include <iostream> #include <vector> #define maxn 110 using namespace std;
const int p = 1000000007; inline int add(int x, int y) { return (x += y) >= p ? x - p : x; } inline int mul(int x, int y) { return 1ll * x * y % p; } inline int add(initializer_list<int> lst) { int s = 0; for (auto t : lst) s = add(s, t); return s; } inline int mul(initializer_list<int> lst) { int s = 1; for (auto t : lst) s = mul(s, t); return s; } int pow_mod(int x, int n) { int s = 1; for (; n; n >>= 1, x = mul(x, x)) if (n & 1) s = mul(s, x); return s; }
int n, m;
struct Edge { int u, v; } e[maxn];
int w[maxn][maxn];
int g[maxn][maxn]; int Gauss(int n) { int res = 1; for (int i = 1; i <= n; ++i) { int pos = -1; for (int j = i; j <= n; ++j) if (g[j][i]) pos = j; if (pos == -1) return 0; swap(g[i], g[pos]); if (pos != i) res = p - res; res = mul(res, g[i][i]); int inv = pow_mod(g[i][i], p - 2); for (int j = i + 1; j <= n; ++j) for (int k = n; k >= i; --k) g[j][k] = add(g[j][k], p - mul({ g[j][i], inv, g[i][k] })); } return res; }
#define Poly vector<int> Poly Lagrange(const Poly &x, const Poly &y, int n) { Poly a(n + 1), b(n + 1); a[0] = 1; for (int i = 1; i <= n; ++i) { for (int j = i; j; --j) a[j] = add(a[j - 1], p - mul(x[i], a[j])); a[0] = p - mul(x[i], a[0]); } Poly res(n); for (int i = 1; i <= n; ++i) { for (int j = n - 1; ~j; --j) b[j] = add(a[j + 1], mul(x[i], b[j + 1])); int t = 1; for (int j = 1; j <= n; ++j) if (i != j) t = mul(t, add(x[i], p - x[j])); t = mul(pow_mod(t, p - 2), y[i]); for (int j = 0; j < n; ++j) res[j] = add(res[j], mul(b[j], t)); } return res; }
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n; for (int i = 1; i < n; ++i) cin >> e[i].u >> e[i].v; vector<int> x(n + 1), y(n + 1); for (int k = 1; k <= n; ++k) { for (int i = 1; i <= n; ++i) g[i][i] = n - 1; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if (i != j) g[i][j] = p - 1; for (int i = 1; i < n; ++i) { int u = e[i].u, v = e[i].v; g[u][u] = add(g[u][u], k - 1), g[v][v] = add(g[v][v], k - 1); g[u][v] = p - k, g[v][u] = p - k; } x[k] = k, y[k] = Gauss(n - 1); } Poly res = Lagrange(x, y, n); for (int i = 0; i < n; ++i) cout << res[i] << " \n"[i == n - 1]; return 0; }
|