Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
//typedef __int128_t lll;
using namespace std;
//-------------------------------------------------------------------
#define P 1000000007
#define N_MAX 10000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
  fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
  for(int i = 2; i <= N_MAX; i++){
    fac[i] = (fac[i-1]*i)%P;
    inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
    finv[i] = (finv[i-1]*inv[i])%P;
  }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
//-------------------------------------------------------------------
vvl G = vv(200001, 0, 0, ll);

vll num(200001, -1), rev(200001, -1), d(200001, 0);
vll ans(200001, 0);

ll f(ll now, ll from){
  if(num[now]!=-1) return num[now];
  ll ret = 1, k = 0;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    ret = (ret * f(G[now][i], now))%P;
    k += d[G[now][i]] + 1;
  }
  d[now] = k;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    ret = (ret * comb(k, d[G[now][i]] + 1))%P;
    k -= d[G[now][i]] + 1;
  }
  return num[now] = ret;
}
ll n;

vll merge(vll a, vll b){
  vll ret = a;
  ret[0] = (((ret[0]*b[0])%P)*comb(ret[1]+b[1], b[1]))%P;
  ret[1] += b[1];
  return ret;
}
void dfs(ll now, ll from, ll R){
  ans[now] = (comb(n-1, d[now])*((R*num[now])%P))%P;
  ll z = n-1-d[now];
  vvl x = vv(0, 2, 0, ll);
  vvl y = vv(0, 2, 0, ll);

  ll c = 0;

  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    x.push_back(vll{0, 0});
    ll to = G[now][i];
    if(c==0) x[c] = vll{num[to], d[to]+1};
    else x[c] = merge(x[c-1], vll{num[to], d[to]+1});
    c++;
  }

  ll t = G[now].size();
  c = 0;
  for(int i=0;i<G[now].size();i++){
    if(G[now][t-1-i]==from) continue;
    y.push_back(vll{0, 0});
    ll to = G[now][t-1-i];
    if(c==0) y[c] = vll{num[to], d[to]+1};
    else y[c] = merge(y[c-1], vll{num[to], d[to]+1});
    c++;
  }
  c = 0;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    vll A = (c==0?vll{1, 0}:x[c-1]);
    vll B = (c==y.size()-1?vll{1, 0}:y[y.size()-2-c]);
    vll C{R, z};
    /*
    std::cout << "to" << G[now][i] << endl;
    std::cout << A[0] << " " << A[1] << '\n';
    std::cout << B[0] << " " << B[1] << '\n';
    std::cout << C[0] << " " << C[1] << '\n';
    */
    A = merge(A, B);
    A = merge(A, C);
    //std::cout << A[0] << " " << A[1] << '\n';
    dfs(G[now][i], now, A[0]);
    c++;
  }
}

int main(int argc, char const *argv[]) {
  ll a, b;std::cin >> n;
  init();
  re(i, n-1) {
    std::cin >> a >> b;
    G[a].push_back(b);G[b].push_back(a);
  }
  ll root = -1;
  for(int i=1;i<=n;i++) {
    if(G[i].size()==1) {
      root = i;
      break;
    }
  }
  f(root, -1);
  dfs(root, -1, 1);
  for(int i=1;i<=n;i++) std::cout << ans[i] << '\n';
  return 0;
}
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
//typedef __int128_t lll;
using namespace std;
//-------------------------------------------------------------------
#define P 1000000007
#define N_MAX 10000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
  fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
  for(int i = 2; i <= N_MAX; i++){
    fac[i] = (fac[i-1]*i)%P;
    inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
    finv[i] = (finv[i-1]*inv[i])%P;
  }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
//-------------------------------------------------------------------
vvl G = vv(200001, 0, 0, ll);

vll num(200001, -1), rev(200001, -1), d(200001, 0);
vll ans(200001, 0);

ll f(ll now, ll from){
  if(num[now]!=-1) return num[now];
  ll ret = 1, k = 0;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    ret = (ret * f(G[now][i], now))%P;
    k += d[G[now][i]] + 1;
  }
  d[now] = k;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    ret = (ret * comb(k, d[G[now][i]] + 1))%P;
    k -= d[G[now][i]] + 1;
  }
  return num[now] = ret;
}
ll n;

vll merge(vll a, vll b){
  vll ret = a;
  ret[0] = (((ret[0]*b[0])%P)*comb(ret[1]+b[1], b[1]))%P;
  ret[1] += b[1];
  return ret;
}
void dfs(ll now, ll from, ll R){
  ans[now] = (comb(n-1, d[now])*((R*num[now])%P))%P;
  ll z = n-1-d[now];
  vvl x = vv(0, 2, 0, ll);
  vvl y = vv(0, 2, 0, ll);

  ll c = 0;

  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    x.push_back(vll{0, 0});
    ll to = G[now][i];
    if(c==0) x[c] = vll{num[to], d[to]+1};
    else x[c] = merge(x[c-1], vll{num[to], d[to]+1});
    c++;
  }

  ll t = G[now].size();
  c = 0;
  for(int i=0;i<G[now].size();i++){
    if(G[now][t-1-i]==from) continue;
    y.push_back(vll{0, 0});
    ll to = G[now][t-1-i];
    if(c==0) y[c] = vll{num[to], d[to]+1};
    else y[c] = merge(y[c-1], vll{num[to], d[to]+1});
    c++;
  }
  c = 0;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    vll A = (c==0?vll{1, 0}:x[c-1]);
    vll B = (c==y.size()-1?vll{1, 0}:y[y.size()-2-c]);
    vll C{R, z};
    /*
    std::cout << "to" << G[now][i] << endl;
    std::cout << A[0] << " " << A[1] << '\n';
    std::cout << B[0] << " " << B[1] << '\n';
    std::cout << C[0] << " " << C[1] << '\n';
    */
    A = merge(A, B);
    A = merge(A, C);
    //std::cout << A[0] << " " << A[1] << '\n';
    dfs(G[now][i], now, A[0]);
    c++;
  }
}

int main(int argc, char const *argv[]) {
  ll a, b;std::cin >> n;
  init();
  re(i, n-1) {
    std::cin >> a >> b;
    G[a].push_back(b);G[b].push_back(a);
  }
  ll root = -1;
  for(int i=1;i<=n;i++) {
    if(G[i].size()==1) {
      root = i;
      break;
    }
  }
  f(root, -1);
  dfs(root, -1, 1);
  for(int i=1;i<=n;i++) std::cout << ans[i] << '\n';
  return 0;
}


Compiler output:
a.cc:175:4: error: redefinition of 'll fac [10000001]'
  175 | ll fac[N_MAX+1];
      |    ^~~
a.cc:30:4: note: 'll fac [10000001]' previously declared here
   30 | ll fac[N_MAX+1];
      |    ^~~
a.cc:176:4: error: redefinition of 'll inv [10000001]'
  176 | ll inv[N_MAX+1];
      |    ^~~
a.cc:31:4: note: 'll inv [10000001]' previously declared here
   31 | ll inv[N_MAX+1];
      |    ^~~
a.cc:177:4: error: redefinition of 'll finv [10000001]'
  177 | ll finv[N_MAX+1];
      |    ^~~~
a.cc:32:4: note: 'll finv [10000001]' previously declared here
   32 | ll finv[N_MAX+1];
      |    ^~~~
a.cc:179:4: error: redefinition of 'll comb(ll, ll)'
  179 | ll comb(ll n, ll k){
      |    ^~~~
a.cc:34:4: note: 'll comb(ll, ll)' previously defined here
   34 | ll comb(ll n, ll k){
      |    ^~~~
a.cc:184:6: error: redefinition of 'void init()'
  184 | void init(){
      |      ^~~~
a.cc:39:6: note: 'void init()' previously defined here
   39 | void init(){
      |      ^~~~
a.cc:192:4: error: redefinition of 'll pp(ll, ll)'
  192 | ll pp(ll a, ll b){
      |    ^~
a.cc:47:4: note: 'll pp(ll, ll)' previously defined here
   47 | ll pp(ll a, ll b){
      |    ^~
a.cc:196:5: error: redefinition of 'std::vector<std::vector<long long int> > G'
  196 | vvl G = vv(200001, 0, 0, ll);
      |     ^
a.cc:51:5: note: 'std::vector<std::vector<long long int> > G' previously declared here
   51 | vvl G = vv(200001, 0, 0, ll);
      |     ^
a.cc:198:5: error: redefinition of 'std::vector<long long int> num'
  198 | vll num(200001, -1), rev(200001, -1), d(200001, 0);
      |     ^~~
a.cc:53:5: note: 'std::vector<long long int> num' previously declared here
   53 | vll num(200001, -1), rev(200001, -1), d(200001, 0);
      |     ^~~
a.cc:198:22: error: redefinition of 'std::vector<long long int> rev'
  198 | vll num(200001, -1), rev(200001, -1), d(200001, 0);
      |                      ^~~
a.cc:53:22: note: 'std::vector<long long int> rev' previously declared here
   53 | vll num(200001, -1), rev(200001, -1), d(200001, 0);
      |                      ^~~
a.cc:198:39: error: redefinition of 'std::vector<long long int> d'
  198 | vll num(200001, -1), rev(200001, -1), d(200001, 0);
      |                                       ^
a.cc:53:39: note: 'std::vector<long long int> d' previously declared here
   53 | vll num(200001, -1), rev(200001, -1), d(200001, 0);
      |                                       ^
a.cc:199:5: error: redefinition of 'std::vector<long long int> ans'
  199 | vll ans(200001, 0);
      |     ^~~
a.cc:54:5: note: 'std::vector<long long int> ans' previously declared here
   54 | vll ans(200001, 0);
      |     ^~~
a.cc:201:4: error: redefinition of 'll f(ll, ll)'
  201 | ll f(ll now, ll from){
      |    ^
a.cc:56:4: note: 'll f(ll, ll)' previously defined here
   56 | ll f(ll now, ll from){
      |    ^
a.cc:217:4: error: redefinition of 'll n'
  217 | ll n;
      |    ^
a.cc:72:4: note: 'll n' previously declared here
   72 | ll n;
      |    ^
a.cc:219:5: error: redefinition of 'std::vector<long long int> merge(std::vector<long long int>, std::vector<long long int>)'
  219 | vll merge(vll a, vll b){
      |     ^~~~~
a.cc:74:5: note: 'std::vector<long long int> merge(std::vector<long long int>, std::vector<long long int>)' previously defined here
   74 | vll merge(vll a, vll b){
      |     ^~~~~
a.cc:225:6: error: redefinition of 'void dfs(ll, ll, ll)'
  225 | void dfs(ll now, ll from, ll R){
      |      ^~~
a.cc:80:6: note: 'void dfs(ll, ll, ll)' previously defined here
   80 | void dfs(ll now, ll from, ll R){
      |      ^~~
a.cc:272:5: error: redefinition of 'int main(int, const char**)'
  272 | int main(int argc, char const *argv[]) {
      |     ^~~~
a.cc:127:5: note: 'int main(int, const char**)' previously defined here
  127 | int main(int argc, char const *argv[]) {
      |     ^~~~