Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using namespace std;
int p =1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
int kai_size = 100001;
vel kai(kai_size, 1);
vel kai2;
vel ink(kai_size, 1);
vel ink2;
vector<int> Centroid(const vector<vector<int>> &g) {
	int n = g.size();
	vector<int> centroid;
	vector<int> sz(n);
	function<void(int, int)> dfs = [&](int u, int prev) {
		sz[u] = 1;
		bool is_centroid = true;
		for (auto v : g[u]) if (v != prev) {
			dfs(v, u);
			sz[u] += sz[v];
			if (sz[v] > n / 2) is_centroid = false;
		}
		if (n - sz[u] > n / 2) is_centroid = false;
		if (is_centroid) centroid.push_back(u);
	};
	dfs(0, -1);
	return centroid;
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	kai2 = kai; ink2 = ink;
	rep(i, kai_size-1) {
		kai[i + 1] = (kai[i] * (i + 1)) % p;
		kai2[i + 1] = kai[i + 1] * kai[i + 1];
		kai2[i + 1] %= p;
	}
	rep(i, kai_size) { 
		ink[i] = inv(kai[i]);
		ink2[i] = ink[i] * ink[i];
		ink2[i] %= p;
	}
}
int size_tree(int back, int now, vvel way) {
	int ans = 1;
	rep(j, way[now].size()) {
		int nex = way[now][j];
		if (nex != back) {
			ans += size_tree(now, nex, way);
		}
	}
	return ans;
}
int center(vvel &way) {
	int n = way.size();
	rep(i, n) {
		int qmax = 0;
		rep(j, way[i].size()) {
			mmax(qmax,size_tree(i, way[i][j], way));
		}
		if (qmax * 2 <= n) { return i; }
	}
	return -1;
}
int RE() {
	vel v(3,2);
	return v.at(4);
}
int comper(int n, int r) {
	int ans = kai2[n] * ink2[n-r];
	ans %= p;
	ans *= ink[r];
	return ans%p;
}
void pl(int &a, int b) {
	a += b; a %= p;
}
signed main() {
	make_kai();
	int n; cin >> n;
	vel x(n), y(n);
	vvel way(n);
	rep(i, n-1) { 
		cin >> x[i] >> y[i]; x[i]--; y[i]--;
		way[x[i]].push_back(y[i]);
		way[y[i]].push_back(x[i]);
	}
	int g = Centroid(way)[0];
	vel sub(0);
	sor(sub);
	rep(i, way[g].size()) {
		sub.push_back(size_tree(g, way[g][i], way));
	}
	int sz = way[g].size();
	vvel dp[5001][5000];
	dp[0][0] = 1;
	int sum = 0;
	rep(i, sz) {
		for (int j = 0; j <= sum; j++) {
			rep(k, sub[i] + 1) {
				int plus = dp[i][j] * comper(sub[i], k);
				pl(dp[i + 1][j + k], plus);
			}
		}
		sum += sub[i];
	}
	int ans = 0;
	int bi = 1;
	rep(i, n) {
		int plus = dp[sz][i] * kai[n - i];
		pl(ans, plus*bi);
		bi *= -1;
	}
	ans += p; ans %= p;
	cout << ans << endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:119:20: error: no match for 'operator=' (operand types are 'std::vector<std::vector<long long int> >' and 'int')
  119 |         dp[0][0] = 1;
      |                    ^
In file included from /usr/include/c++/14/vector:72,
                 from a.cc:3:
/usr/include/c++/14/bits/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'int' to 'const std::vector<std::vector<long long int> >&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'int' to 'std::vector<std::vector<long long int> >&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<std::vector<long long int> >'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:124:53: error: no match for 'operator*' (operand types are 'std::vector<std::vector<long long int> >' and 'long long int')
  124 |                                 int plus = dp[i][j] * comper(sub[i], k);
      |                                            ~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~
      |                                                   |         |
      |                                                   |         long long int
      |                                                   std::vector<std::vector<long long int> >
a.cc:125:51: error: invalid initialization of reference of type 'long long int&' from expression of type 'std::vector<std::vector<long long int> >'
  125 |                                 pl(dp[i + 1][j + k], plus);
      |                                    ~~~~~~~~~~~~~~~^
a.cc:98:14: note: in passing argument 1 of 'void pl(long long int&, long long int)'
   98 | void pl(int &a, int b) {
      |              ^
a.cc:133:38: error: no match for 'operator*' (operand types are 'std::vector<std::vector<long long int> >' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
  133 |                 int plus = dp[sz][i] * kai[n - i];