Language: C++

#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;

#define double long double
//#define int long long
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << '\n';
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; };
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; };

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}

const int N = 2e5 + 10;
int e[N][2];
vector<pii> g[N];
int dp[N][2];
int sz[N][2];
const int mod = 1e9 + 7;
int fact[N];
int rfact[N];

int mult(int &a, int &b) {
	ll c = a;
	c *= b;
	if (c >= mod) return c % mod;
	return c;
}

int binpow(int a, int b) {
	if (b == 0) return 1;
	if (b & 1) return mult(a, binpow(a, b - 1));
	return binpow(mult(a, a), b / 2);
}

int rev(int x) {
	return binpow(x, mod - 2);
}

void dfs(int numE, int t) {
	if (dp[numE][t] != -1) return;
	dp[numE][t] = 1;
	for (pii eto : g[e[numE][t]]) {
		if (eto.fi == numE) continue;
		dfs(eto.fi, eto.se);
		sz[numE][t] += sz[eto.fi][eto.se];
		dp[numE][t] = mult(dp[numE][t], rfact[sz[eto.fi][eto.se]]);
		dp[numE][t] = mult(dp[numE][t], dp[eto.fi][eto.se]);
	}
	dp[numE][t] = mult(dp[numE][t], fact[sz[numE][t]]);
	sz[numE][t]++;
}


signed main() {
	fast();
	fact[0] = 1;
	for (int i = 1; i < N; i++) {
		fact[i] = mult(fact[i - 1], i);
	}
	rfact[N - 1] = rev(fact[N - 1]);
	for (int i = N - 2; i >= 0; i--) {
		rfact[i] = mult(rfact[i + 1], i + 1);
	}
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> e[i][0] >> e[i][1];
		e[i][0]--; e[i][1]--;
		g[e[i][0]].pb(mp(i, 1));
		g[e[i][1]].pb(mp(i, 0));
	}
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < n - 1; i++) {
		for (int t = 0; t < 2; t++) {
			dfs(i, t);
		}
	}
	for (int i = 0; i < n; i++) {
		int ans = 1;
		int curSz = 0;
		for (pii eto : g[i]) {
			curSz += sz[eto.fi][eto.se];
			ans = mult(ans, rfact[sz[eto.fi][eto.se]]);
			ans = mult(ans, dp[eto.fi][eto.se]);
		}
		ans = mult(ans, fact[curSz]);
		cout << ans << '\n';
	}
 	return 0;
}

Compiler output:
a.cc: In function 'int binpow(int, int)':
a.cc:54:41: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   54 |         if (b & 1) return mult(a, binpow(a, b - 1));
      |                                   ~~~~~~^~~~~~~~~~
a.cc:45:23: note:   initializing argument 2 of 'int mult(int&, int&)'
   45 | int mult(int &a, int &b) {
      |                  ~~~~~^
a.cc: In function 'int main()':
a.cc:85:49: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   85 |                 rfact[i] = mult(rfact[i + 1], i + 1);
      |                                               ~~^~~
a.cc:45:23: note:   initializing argument 2 of 'int mult(int&, int&)'
   45 | int mult(int &a, int &b) {
      |                  ~~~~~^