Language: C++

#include <iostream>
#include <vector>
using namespace std;

int N;
vector<vector<int>> E;

long long Fact[200001];

const long long Mod = 1000000007;

vector<vector<long, long>> Memo;
vector<vector<int>> CMemo;

long long Pow(long long n, long long m) {
	long long res = 1;
	while (m > 0) {
		if (m % 2 == 1) {
			res *= n;
			res %= Mod;
		}
		n *= n;
		n %= Mod;
		m /= 2;
	}
	return res;
}

long long C(int n, int m) {
	long long a = Fact[n];
	long long b = (Fact[m] * Fact[n - m]) % Mod;
	return (a * Pow(b, Mod - 2)) % Mod;
}

long long Search(int n, int p, int num, int& cnt)
{
	if (num != -1 && CMemo[p][num] != -1) {
		cnt = CMemo[p][num];
		return Memo[p][num];
	}

	long long res = 1;
	int sum = 0;
	for (int i = 0; i < E[n].size; i++)
	{
		int to = E[n][i];
		if (to == p) continue;
		int ou;
		long long r = Search(to, n, i, ou);
		sum += ou;
		res *= (C(sum, ou) * r)%Mod;
		res %= Mod;
	}

	sum++;
	if (num != -1)
	{
		CMemo[p][num] = sum;
		Memo[p][num] = res;
	}
	cnt = sum;
	return res;
}

int main()
{
	cin >> N;
	E.resize(N);
	for (size_t i = 0; i < N - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		E[a - 1].push_back(b - 1);
		E[b - 1].push_back(a - 1);
	}

	Fact[0] = 1;
	for (size_t i = 1; i <= 200000; i++)
	{
		Fact[i] = Fact[i - 1] * i;
		Fact[i] %= Mod;
	}

	Memo.resize(N);
	CMemo.resize(N);
	for (size_t i = 0; i < N; i++)
	{
		Memo[i].resize(E[i].size());
		CMemo[i].resize(E[i].size());
		for (size_t j = 0; j < E[i].size; j++)
		{
			CMemo[i][j] = -1;
		}
	}

	for (int i = 0; i < N; i++) {
		int o;
		cout << Search(i, -1, -1, o) << "\n";
	}

	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'struct std::_Vector_base<long int, long int>':
/usr/include/c++/14/bits/stl_vector.h:428:11:   required from 'class std::vector<long int, long int>'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
a.cc:39:21:   required from here
   39 |                 return Memo[p][num];
      |                                   ^
/usr/include/c++/14/bits/stl_vector.h:87:28: error: 'long int' is not a class, struct, or union type
   87 |         rebind<_Tp>::other _Tp_alloc_type;
      |                            ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:89:9: error: 'long int' is not a class, struct, or union type
   89 |         pointer;
      |         ^~~~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'class std::vector<long int, long int>':
a.cc:39:21:   required from here
   39 |                 return Memo[p][num];
      |                                   ^
/usr/include/c++/14/bits/stl_vector.h:518:20: error: '_M_allocate' has not been declared in 'std::vector<long int, long int>::_Base'
  518 |       using _Base::_M_allocate;
      |                    ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:519:20: error: '_M_deallocate' has not been declared in 'std::vector<long int, long int>::_Base'
  519 |       using _Base::_M_deallocate;
      |                    ^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:521:20: error: '_M_get_Tp_allocator' has not been declared in 'std::vector<long int, long int>::_Base'
  521 |       using _Base::_M_get_Tp_allocator;
      |                    ^~~~~~~~~~~~~~~~~~~
a.cc: In function 'long long int Search(int, int, int, int&)':
a.cc:39:31: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long int, long int> >, std::vector<long int, long int> >::value_type' {aka 'std::vector<long int, long int>'} and 'int')
   39 |                 return Memo[p][num];
      |                               ^
a.cc:44:34: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?)
   44 |         for (int i = 0; i < E[n].size; i++)
      |                                      ()
a.cc:59:24: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long int, long int> >, std::vector<long int, long int> >::value_type' {aka 'std::vector<long int, long int>'} and 'int')
   59 |                 Memo[p][num] = res;
      |                        ^
a.cc: In function 'int main()':
a.cc:90:45: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?)
   90 |                 for (size_t j = 0; j < E[i].size; j++)
      |                                                 ()
In file included from /usr/include/c++/14/bits/requires_hosted.h:31,
                 from /usr/include/c++/14/iostream:38,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_Vector_impl() [with _Tp = long int; _Alloc = long int]':
/usr/include/c++/14/bits/stl_construct.h:119:7:   required from 'void std::_Construct(_Tp*, _Args&& ...) [with _Tp = vector<long int, long int>; _Args = {}]'
  119 |       ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:643:18:   required from 'static _ForwardIterator std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = std::vector<long int, long int>*; _Size = long unsigned int; bool _TrivialValueType = false]'
  643 |                 std::_Construct(std::__addressof(*__cur));
      |                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:712:20:   required from '_ForwardIterator std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = vector<long int, long int>*; _Size = long unsigned int]'
  710 |       return __uninitialized_default_n_1<__is_trivial(_ValueType)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  711 |                                          && __can_fill>::
      |                                          ~~~~~~~~~~~~~~~~
  712 |         __uninit_default_n(__first, __n);
      |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:779:44:   required from '_ForwardIterator std::__uninitialized_default_n_a(_ForwardIterator, _Size, allocator<_Tp>&) [with _ForwardIterator = vector<long int, long int>*; _Size = long unsigned int; _Tp = vector<long int, long int>]'
  779 |     { return std::__uninitialized_default_n(__first, __n); }
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:821:35:   required from 'void std::vector<_Tp, _Alloc>::_M_default_append(size_type) [with _Tp = std::vector<long int, long int>; _Alloc = std::allocator<std::vector<long int, long int> >; size_type = long unsigned int]'
  821 |                 std::__uninitialized_default_n_a(this->_M_impl._M_finish,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
  822 |                                                  __n, _M_get_Tp_allocator());
      |                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1016:4:   required from 'void std::vector<_Tp, _Alloc>::resize(size_type) [with _Tp = std::vector<long int, long int>; _Alloc = std::allocator<std::vector<long int, long int> >; size_type = long unsigned int]'
 1016 |           _M_default_append(__new_size - size());
      |           ^~~~~~~~~~~~~~~~~
a.cc:84:13:   required from here
   84 |         Memo.resize(N);
      |         ~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:136:24: error: 'long int' is not a class, struct, or union type
  136 |         _Vector_impl() _GLIBCXX_NOEXCEPT_IF(
      |                        ^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_Vector_impl(std::_Vector_base<_Tp, _Alloc>::_Vector_impl&&) [with _Tp = long int; _Alloc = long int]':
/usr/include/c++/14/bits/stl_vector.h:337:7:   required from 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::vector<long int, long int>; _Args = {std::vector<long int, long int>}; _Tp = std::vector<long int, long int>]'
  337 |       _Vector_base(_Vector_base&&) = default;
      |       ^~~~~~~~~~~~
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::vector<long int, long int>; _Args = {std::vector<long int, long int>}; _Tp = std::vector<long int, long int>; allocator_type = std::allocator<std::vector<long int, long int> >]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:1075:26:   required from 'void std::__relocate_object_a(_Tp*, _Up*, _Allocator&) [with _Tp = vector<long int, long int>; _Up = vector<long int, long int>; _Allocator = allocator<vector<long int, long int> >]'
 1075 |       __traits::construct(__alloc, __dest, std::move(*__orig));
      |       ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:1103:26:   required from '_ForwardIterator std::__relocate_a_1(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = vector<long int, long int>*; _ForwardIterator = vector<long int, long int>*; _Allocator = allocator<vector<long int, long int> >]'
 1103 |         std::__relocate_object_a(std::__addressof(*__cur),
      |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
 1104 |                                  std::__addressof(*__first), __alloc);
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:1145:33:   required from '_ForwardIterator std::__relocate_a(_InputIterator, _InputIterator, _ForwardIterator, _Allocator&) [with _InputIterator = vector<long int, long int>*; _ForwardIterator = vector<long int, long int>*; _Allocator = allocator<vector<long int, long int> >]'
 1145 |       return std::__relocate_a_1(std::__niter_base(__first),
      |              ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1146 |                                  std::__niter_base(__last),
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
 1147 |                                  std::__niter_base(__result), __alloc);
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:509:26:   required from 'static std::vector<_Tp, _Alloc>::pointer std::vector<_Tp, _Alloc>::_S_relocate(pointer, pointer, pointer, _Tp_alloc_type&) [with _Tp = std::vector<long int, long int>; _Alloc = std::allocator<std::vector<long int, long int> >; pointer = std::vector<long int, long int>*; _Tp_alloc_type = std::vector<std::vector<long int, long int> >::_Tp_alloc_type]'
  509 |         return std::__relocate_a(__first, __last, __result, __alloc);
      |                ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:868:18:   required from 'void std::vector<_Tp, _Alloc>::_M_default_append(size_type) [with _Tp = std::vector<long int, long int>; _Alloc = std::allocator<std::vector<long int, long int> >; size_type = long unsigned int]'
  868 |                     _S_relocate(__old_start, __old_finish,
      |                     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~