Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;


class modInt{
    ll value;
    static const ll mod = 1000000007;

public:
    modInt(ll x): value{x % mod}{}

    inline modInt& operator+=(modInt x){
        value = (value + x.value) % mod;
        return *this;
    }

    inline modInt& operator-=(modInt x){
        value = (value + mod - x.value) % mod;
        return *this;
    }

    inline modInt& operator*=(modInt x){
        value = (value * x.value) % mod;
        return *this;
    }


    inline modInt operator/=(modInt x){
        *this *= x.inv();
        return *this;
    }

    inline modInt pow(modInt x, int n){
        modInt res = modInt(1LL);
        while(n > 0){
            if(n & 1)   res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }

    inline modInt inv(){
        modInt res = pow(value, mod-2);
        return res;
    }

    inline ll get(){
        return value;
    }
};

modInt operator+(modInt x, modInt y){
    return x += y;
}

modInt operator-(modInt x, modInt y){
    return x -= y;
}

modInt operator*(modInt x, modInt y){
    return x *= y;
}

modInt operator/(modInt x, modInt y){
    return x /= y;
}

ostream& operator<<(ostream& os, modInt x){
    return os << x.get();
}


class modIntCombinations{
    vector<modInt> factArray;

    void make_fact(ll x){
        for(auto i = factArray.size(); i <= x+1; i++){
            modInt y = factArray[i-1] * i;
            factArray.push_back(y);
        }
    }

public:
    modIntCombinations(){
        factArray.emplace_back(1);
    }

    modInt fact(ll x){
        if(factArray.size() < x+1){
            make_fact(x);
        }
        return factArray[x];
    }

    modInt comb(ll n, ll k){
        if(n < k){
            return modInt{0};
        }
        else{
            return fact(n) / fact(k) / fact(n - k);
        }
    }

    modInt perm(ll n, ll k){
        if(n < k){
            return modInt{0};
        }
        else{
            return fact(n) / fact(k);
        }
    }
};


class Graph{
    struct edge{
        int vertice;
        ll weight;
    };

    vector<vector<edge>> g;
    unsigned int n;

public:
    Graph(unsigned int n): n{n}{
        g.resize(n);
    }

    void add_edge(int u, int v){
        g[u].emplace_back(edge{v, 1});
    };

    void add_edge(int u, int v, ll w){
        g[u].emplace_back(edge{v, w});
    }

    vector<edge>& get_edge(int v){
        return g[v];
    }

    unsigned int get_num_vertices(){
        return n;
    }

    vector<edge>& operator[](int v){
        return get_edge(v);
    }
};

int child[201000];
vector<modInt> childRes(201000);
map<int, modInt> mp[201000];
vector<modInt> resList(201000);


modInt dfs(int v, int prev, Graph& g, modIntCombinations& mic){
    modInt res = modInt{1};
    int num = 0, childSum = 0;
    for(auto u: g[v]){
        if(u.vertice == prev)   continue;
        modInt x = dfs(u.vertice, v, g, mic);
        res *= x;
        num += child[u.vertice];
        childSum += child[u.vertice];
    }
    for(auto u: g[v]){
        if(u.vertice == prev) continue;
        int childNum = child[u.vertice];
        res *= mic.comb(num, childNum);
        num -= childNum;
    }
    childSum++;
    child[v] = childSum;
    childRes[v] = res;

    return res;
}

void dfs2(int v, int prev, Graph& g, modIntCombinations& mic, int N){
    modInt res = childRes[v];
    int remained = N - child[v];
    res *= mic.comb(N-1, remained);
    res *= mp[prev][v];
    resList[v] = res;

    for(auto u: g[v]){
        mp[v][u.vertice] = res / mic.comb(N-1, child[u.vertice]) / childRes[u.vertice];
        dfs2(u.vertice, v, g, mic, N);
    }
}


int main(){
    int N;
    cin >> N;
    Graph g(N);
    for(int i = 0; i < N-1; i++){
        int a, b;   cin >> a >> b;
        a--; b--;
        g.add_edge(a, b);
        g.add_edge(b, a);
    }
    modIntCombinations mic{};

    modInt res1 = dfs(0, 0, g, mic);
    for(auto u: g[0]){
        mp[0][u.vertice] = res1 / mic.comb(N-1, child[u.vertice]) / childRes[u.vertice];
        dfs2(u.vertice, 0, g, mic, N);
    }

    for(int i = 0; i < N; i++){
        cout << resList[i] << endl;
    }



    return 0;
}

Compiler output:
In file included from /usr/include/c++/14/bits/alloc_traits.h:33,
                 from /usr/include/c++/14/ext/alloc_traits.h:34,
                 from /usr/include/c++/14/bits/basic_string.h:39,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_construct.h: In instantiation of 'void std::_Construct(_Tp*, _Args&& ...) [with _Tp = modInt; _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 = modInt*; _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 = modInt*; _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 = modInt*; _Size = long unsigned int; _Tp = modInt]'
  779 |     { return std::__uninitialized_default_n(__first, __n); }
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1720:36:   required from 'void std::vector<_Tp, _Alloc>::_M_default_initialize(size_type) [with _Tp = modInt; _Alloc = std::allocator<modInt>; size_type = long unsigned int]'
 1720 |           std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1721 |                                            _M_get_Tp_allocator());
      |                                            ~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:558:9:   required from 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = modInt; _Alloc = std::allocator<modInt>; size_type = long unsigned int; allocator_type = std::allocator<modInt>]'
  558 |       { _M_default_initialize(__n); }
      |         ^~~~~~~~~~~~~~~~~~~~~
a.cc:181:31:   required from here
  181 | vector<modInt> childRes(201000);
      |                               ^
/usr/include/c++/14/bits/stl_construct.h:119:7: error: no matching function for call to 'modInt::modInt()'
  119 |       ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:39:5: note: candidate: 'modInt::modInt(ll)'
   39 |     modInt(ll x): value{x % mod}{}
      |     ^~~~~~
a.cc:39:5: note:   candidate expects 1 argument, 0 provided
a.cc:34:7: note: candidate: 'constexpr modInt::modInt(const modInt&)'
   34 | class modInt{
      |       ^~~~~~
a.cc:34:7: note:   candidate expects 1 argument, 0 provided
a.cc:34:7: note: candidate: 'constexpr modInt::modInt(modInt&&)'
a.cc:34:7: note:   candidate expects 1 argument, 0 provided
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68:
/usr/include/c++/14/tuple: In instantiation of 'std::pair<_T1, _T2>::pair(std::tuple<_Args1 ...>&, std::tuple<_Args2 ...>&, std::_Index_tuple<_Indexes1 ...>, std::_Index_tuple<_Indexes2 ...>) [with _Args1 = {const int&}; long unsigned int ..._Indexes1 = {0}; _Args2 = {}; long unsigned int ..._Indexes2 = {}; _T1 = const int; _T2 = modInt]':
/usr/include/c++/14/tuple:2879:63:   required from 'std::pair<_T1, _T2>::pair(std::piecewise_construct_t, std::tuple<_Args1 ...>, std::tuple<_Args2 ...>) [with _Args1 = {const int&}; _Args2 = {}; _T1 = const int; _T2 = modInt]'
 2879 |              typename _Build_index_tuple<sizeof...(_Args2)>::__type())
      |                                                                      ^
/usr/include/c++/14/bits/new_allocator.h:191:4:   required from 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::pair<const int, modInt>; _Args = {const std::piecewise_construct_t&, std::tuple<const int&>, std::tuple<>}; _Tp = std::_Rb_tree_node<std::pair<const int, modInt> >]'
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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::pair<const int, modInt>; _Args = {const std::piecewise_construct_t&, std::tuple<const int&>, std::tuple<>}; _Tp = std::_Rb_tree_node<std::pair<const int, modInt> >; allocator_type = std::allocator<std::_Rb_tree_node<std::pair<const int, modInt> > >]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:593:32:   required from 'void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_construct_node(_Link_type, _Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<const int&>, std::tuple<>}; _Key = int; _Val = std::pair<const int, modInt>; _KeyOfValue = std::_Select1st<std::pair<const int, modInt> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, modInt> >; _Link_type = std::_Rb_tree_node<std::pair<const int, modInt> >*]'
  593 |               _Alloc_traits::construct(_M_get_Node_allocator(),
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
  594 |                                        __node->_M_valptr(),
      |                                        ~~~~~~~~~~~~~~~~~~~~
  595 |                                        std::forward<_Args>(__args)...);
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:610:21:   required from 'std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_create_node(_Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<const int&>, std::tuple<>}; _Key = int; _Val = std::pair<const int, modInt>; _KeyOfValue = std::_Select1st<std::pair<const int, modInt> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, modInt> >; _Link_type = std::_Rb_tree_node<std::pair<const int, modInt> >*]'
  610 |           _M_construct_node(__tmp, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1633:32:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Auto_node::_Auto_node(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, _Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<const int&>, std::tuple<>}; _Key = int; _Val = std::pair<const int, modInt>; _KeyOfValue = std::_Select1st<std::pair<const int, modInt> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, modInt> >]'
 1633 |             _M_node(__t._M_create_node(std::forward<_Args>(__args)...))
      |                     ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:2460:13:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_emplace_hint_unique(const_iterator, _Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<const int&>, std::tuple<>}; _Key = int; _Val = std::pair<const int, modInt>; _KeyOfValue = std::_Select1st<std::pair<const int, modInt> >; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, modInt> >; iterator = std::_Rb_tree<int, std::pair<const int, modInt>, std::_Select1st<std::pair<const int, modInt> >, std::less<int>, std::allocator<std::pair<const int, modInt> > >::iterator; const_iterator = std::_Rb_tree<int, std::pair<const int, modInt>, std::_Select1st<std::pair<const int, modInt> >, std::less<int>, std::allocator<std::pair<const int, modInt> > >::const_iterator]'
 2460 |         _Auto_node __z(*this, std::forward<_Args>(__args)...);
      |                    ^~~
/usr/include/c++/14/bits/stl_map.h:513:37:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = int; _Tp = modInt; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, modInt> >; mapped_type = modInt; key_type = int]'
  513 |           __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  514 |                                             std::tuple<const key_type&>(__k),
      |                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  515 |                                             std::tuple<>());
      |                                             ~~~~~~~~~~~~~~~
a.cc:213:22:   required from here
  213 |     res *= mp[prev][v];
      |                      ^
/usr/include/c++/14/tuple:2890:9: error: no matching function for call to 'modInt::modInt()'
 2890 |         second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:39:5: note: candidate: 'modInt::modInt(ll)'
   39 |     modInt(ll x): value{x % mod}{}
      |     ^~~~~~
a.cc:39:5: note:   candidate