Language: C++

// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <fstream>
#include <stdio.h>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

long long pow(long long n, long long p, long long k) {//n^k(mod p)
	if (!k) return 1;
	long long a = pow(n, p, k >> 1);
	a = a * a%p;
	if (k & 1) a = a * n%p;
	return a;
}
void euclid(long long &a, long long &b, long long p) { // a>=b A*b+B*(a-a/b*b)=1
	if (a == 1) {
		a = 1;
	}
	else {
		long long A = b, B = a % b;
		euclid(A, B, p);
		b = (A - (p + a / b) % p * B % p + p) % p;
		a = B;
	}
}
long long rev(long long n, long long p) {//nの逆元 n*x-p*y=1
	//long long q = p;
	//euclid(p, n, p);
	//return n % q;
	return pow(n, p, p - 2);
}
long long bino(long long n, long long m, long long p) {//nCm(mod p)
	long long ans = 1, div = 1;
	for (int i = 0;i < m; i++) {
		ans = (n - i) * ans % p;
		div = div * (i + 1) % p;
	}
	return ans * rev(div, p) % p;
}
struct modint {
	long long num;
	long long p;
	modint() {
		num = 0;
		p = 1000000007;
	}
	modint(int x) {
		p = 1000000007;
		num = (long long)x%p;
	}
	modint(long long x) {
		p = 1000000007;
		num = x % p;
	}
	modint operator+(const modint &other) {
		modint ret;
		ret.p = p;
		ret.num = (num + other.num) % p;
		return ret;
	}
	modint operator+(const long long &other) {
		modint ret;
		ret.p = p;
		ret.num = (num + (other%p)) % p;
		return ret;
	}
	modint operator-(const modint &other) {
		modint ret;
		ret.p = p;
		ret.num = (num - other.num + p) % p;
		return ret;
	}
	modint operator-(const long long &other) {
		modint ret;
		ret.p = p;
		ret.num = (num - (other%p) + p) % p;
		return ret;
	}
	modint operator*(const modint &other) {
		modint ret;
		ret.p = p;
		ret.num = (num*other.num) % p;
		return ret;
	}
	modint operator*(const long long &other) {
		modint ret;
		ret.p = p;
		ret.num = (num*(other%p)) % p;
		return ret;
	}
	modint operator/(const modint &other) {
		modint ret;
		ret.p = p;
		ret.num = (num*rev(other.num, p)) % p;
		return ret;
	}
	modint operator/(const long long &other) {
		modint ret;
		ret.p = p;
		ret.num = (num*rev(other%p, p)) % p;
		return ret;
	}
	void operator+=(const long long &other) {
		num = (num + other) % p;
	}
	void operator+=(const modint &other) {
		num = (num + other.num) % p;
	}
	void operator-=(const long long &other) {
		num = (num - other + p) % p;
	}
	void operator-=(const modint &other) {
		num = (num - other.num + p) % p;
	}
	void operator*=(const long long &other) {
		num = (num*other) % p;
	}
	void operator*=(const modint &other) {
		num = (num*other.num) % p;
	}
};
std::ostream& operator<<(std::ostream &os, const modint &x) {
	std::cout << x.num;
	return os;
}

using namespace std;

struct P {
	int to, si;
	modint c;
	bool flag;
	P() {}
	P(int _to) {
		to = _to;
		si = 1;
		flag = false;
	}
};

vector<modint> li(220000);
vector<modint> inv(220000);
vector<modint> gg(220000);

modint cal(vector<int> &da) {
	modint ret(1);
	int co = 0;
	rip(i, da.size(), 0) {
		co += da[i];
		ret *= inv[da[i]];
	}
	ret *= li[co];
	return ret;
}

void rec(int x, int y, int z, vector<vector<P>> &da) {//x->y
	if (da[x][z].flag) return;
	modint ret(1);
	vector<int> me(0);
	rip(i, da[y].size(), 0) {
		if (da[y][i].to == x) continue;
		rec(y, da[y][i].to, i, da);
		ret *= da[y][i].c;
		me.push_back(da[y][i].si);
		da[x][z].si += da[y][i].si;
	}
	ret *= cal(me);
	da[x][z].c = ret;
	da[x][z].flag = true;
	return;
}

modint ans_cal(int x, vector<vector<P>> &da) {
	modint ret(1);
	vector<int> me(0);
	rip(i, da[x].size(), 0) ret *= da[x][i].c, me.push_back(da[x][i].si);
	ret *= cal(me);
	return ret;
}

int main() {
	li[0].num = 1;
	inv[0].num = 1;
	rip(i, 220000, 1) {
		li[i] = li[i - 1] * i;
		inv[i] = rev(li[i].num, 1000000007);
	}
	int n; cin >> n;
	vector<vector<P>> da(n, vector<P>(0));
	rip(i, n-1, 0) {
		int a, b; cin >> a >> b;
		a--;b--;
		da[a].push_back(P(b));
		da[b].push_back(P(a));
	}
	rip(i, n, 0) {
		rip(j, da[i].size(), 0) rec(i, da[i][j].to, j, da);
	}
	vector<modint> ans(n);
	rip(i, n, 0) {
		ans[i] = ans_cal(i, da);
	}
	rip(i, n, 0) cout << ans[i] << endl;
}// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <fstream>
#include <stdio.h>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

long long pow(long long n, long long p, long long k) {//n^k(mod p)
	if (!k) return 1;
	long long a = pow(n, p, k >> 1);
	a = a * a%p;
	if (k & 1) a = a * n%p;
	return a;
}
void euclid(long long &a, long long &b, long long p) { // a>=b A*b+B*(a-a/b*b)=1
	if (a == 1) {
		a = 1;
	}
	else {
		long long A = b, B = a % b;
		euclid(A, B, p);
		b = (A - (p + a / b) % p * B % p + p) % p;
		a = B;
	}
}
long long rev(long long n, long long p) {//nの逆元 n*x-p*y=1
	//long long q = p;
	//euclid(p, n, p);
	//return n % q;
	return pow(n, p, p - 2);
}
long long bino(long long n, long long m, long long p) {//nCm(mod p)
	long long ans = 1, div = 1;
	for (int i = 0;i < m; i++) {
		ans = (n - i) * ans % p;
		div = div * (i + 1) % p;
	}
	return ans * rev(div, p) % p;
}
struct modint {
	long long num;
	long long p;
	modint() {
		num = 0;
		p = 1000000007;
	}
	modint(int x) {
		p = 1000000007;
		num = (long long)x%p;
	}
	modint(long long x) {
		p = 1000000007;
		num = x % p;
	}
	modint operator+(const modint &other) {
		modint ret;
		ret.p = p;
		ret.num = (num + other.num) % p;
		return ret;
	}
	modint operator+(const long long &other) {
		modint ret;
		ret.p = p;
		ret.num = (num + (other%p)) % p;
		return ret;
	}
	modint operator-(const modint &other) {
		modint ret;
		ret.p = p;
		ret.num = (num - other.num + p) % p;
		return ret;
	}
	modint operator-(const long long &other) {
		modint ret;
		ret.p = p;
		ret.num = (num - (other%p) + p) % p;
		return ret;
	}
	modint operator*(const modint &other) {
		modint ret;
		ret.p = p;
		ret.num = (num*other.num) % p;
		return ret;
	}
	modint operator*(const long long &other) {
		modint ret;
		ret.p = p;
		ret.num = (num*(other%p)) % p;
		return ret;
	}
	modint operator/(const modint &other) {
		modint ret;
		ret.p = p;
		ret.num = (num*rev(other.num, p)) % p;
		return ret;
	}
	modint operator/(const long long &other) {
		modint ret;
		ret.p = p;
		ret.num = (num*rev(other%p, p)) % p;
		return ret;
	}
	void operator+=(const long long &other) {
		num = (num + other) % p;
	}
	void operator+=(const modint &other) {
		num = (num + other.num) % p;
	}
	void operator-=(const long long &other) {
		num = (num - other + p) % p;
	}
	void operator-=(const modint &other) {
		num = (num - other.num + p) % p;
	}
	void operator*=(const long long &other) {
		num = (num*other) % p;
	}
	void operator*=(const modint &other) {
		num = (num*other.num) % p;
	}
};
std::ostream& operator<<(std::ostream &os, const modint &x) {
	std::cout << x.num;
	return os;
}

using namespace std;

struct P {
	int to, si;
	modint c;
	bool flag;
	P() {}
	P(int _to) {
		to = _to;
		si = 1;
		flag = false;
	}
};

vector<modint> li(220000);
vector<modint> inv(220000);
vector<modint> gg(220000);

modint cal(vector<int> &da) {
	modint ret(1);
	int co = 0;
	rip(i, da.size(), 0) {
		co += da[i];
		ret *= inv[da[i]];
	}
	ret *= li[co];
	return ret;
}

void rec(int x, int y, int z, vector<vector<P>> &da) {//x->y
	if (da[x][z].flag) return;
	modint ret(1);
	vector<int> me(0);
	rip(i, da[y].size(), 0) {
		if (da[y][i].to == x) continue;
		rec(y, da[y][i].to, i, da);
		ret *= da[y][i].c;
		me.push_back(da[y][i].si);
		da[x][z].si += da[y][i].si;
	}
	ret *= cal(me);
	da[x][z].c = ret;
	da[x][z].flag = true;
	return;
}

modint ans_cal(int x, vector<vector<P>> &da) {
	modint ret(1);
	vector<int> me(0);
	rip(i, da[x].size(), 0) ret *= da[x][i].c, me.push_back(da[x][i].si);
	ret *= cal(me);
	return ret;
}

int main() {
	li[0].num = 1;
	inv[0].num = 1;
	rip(i, 220000, 1) {
		li[i] = li[i - 1] * i;
		inv[i] = rev(li[i].num, 1000000007);
	}
	int n; cin >> n;
	vector<vector<P>> da(n, vector<P>(0));
	rip(i, n-1, 0) {
		int a, b; cin >> a >> b;
		a--;b--;
		da[a].push_back(P(b));
		da[b].push_back(P(a));
	}
	rip(i, n, 0) {
		rip(j, da[i].size(), 0) rec(i, da[i][j].to, j, da);
	}
	vector<modint> ans(n);
	rip(i, n, 0) {
		ans[i] = ans_cal(i, da);
	}
	rip(i, n, 0) cout << ans[i] << endl;
}

Compiler output:
a.cc:303:13: error: redefinition of 'template<class T> bool chmax(T&, T)'
  303 | inline bool chmax(T &a, T b) {
      |             ^~~~~
a.cc:38:13: note: 'template<class T> bool chmax(T&, T)' previously declared here
   38 | inline bool chmax(T &a, T b) {
      |             ^~~~~
a.cc:311:13: error: redefinition of 'template<class T> bool chmin(T&, T)'
  311 | inline bool chmin(T &a, T b) {
      |             ^~~~~
a.cc:46:13: note: 'template<class T> bool chmin(T&, T)' previously declared here
   46 | inline bool chmin(T &a, T b) {
      |             ^~~~~
a.cc:320:16: error: redefinition of 'template<class T> std::vector<_Tp> vec(int, T)'
  320 | std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
      |                ^~~
a.cc:55:16: note: 'template<class T> std::vector<_Tp> vec(int, T)' previously declared here
   55 | std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
      |                ^~~
a.cc:322:6: error: redefinition of 'template<class T> void vdeb(std::vector<_Tp>&)'
  322 | void vdeb(std::vector<T> &da) {
      |      ^~~~
a.cc:57:6: note: 'template<class T> void vdeb(std::vector<_Tp>&)' previously declared here
   57 | void vdeb(std::vector<T> &da) {
      |      ^~~~
a.cc:330:6: error: redefinition of 'template<class T> void vdeb(std::vector<std::vector<_Tp> >&)'
  330 | void vdeb(std::vector<std::vector<T>> &da) {
      |      ^~~~
a.cc:65:6: note: 'template<class T> void vdeb(std::vector<std::vector<_Tp> >&)' previously declared here
   65 | void vdeb(std::vector<std::vector<T>> &da) {
      |      ^~~~
a.cc:335:11: error: redefinition of 'long long int pow(long long int, long long int, long long int)'
  335 | long long pow(long long n, long long p, long long k) {//n^k(mod p)
      |           ^~~
a.cc:70:11: note: 'long long int pow(long long int, long long int, long long int)' previously defined here
   70 | long long pow(long long n, long long p, long long k) {//n^k(mod p)
      |           ^~~
a.cc:342:6: error: redefinition of 'void euclid(long long int&, long long int&, long long int)'
  342 | void euclid(long long &a, long long &b, long long p) { // a>=b A*b+B*(a-a/b*b)=1
      |      ^~~~~~
a.cc:77:6: note: 'void euclid(long long int&, long long int&, long long int)' previously defined here
   77 | void euclid(long long &a, long long &b, long long p) { // a>=b A*b+B*(a-a/b*b)=1
      |      ^~~~~~
a.cc:353:11: error: redefinition of 'long long int rev(long long int, long long int)'
  353 | long long rev(long long n, long long p) {//nの逆元 n*x-p*y=1
      |           ^~~
a.cc:88:11: note: 'long long int rev(long long int, long long int)' previously defined here
   88 | long long rev(long long n, long long p) {//nの逆元 n*x-p*y=1
      |           ^~~
a.cc:359:11: error: redefinition of 'long long int bino(long long int, long long int, long long int)'
  359 | long long bino(long long n, long long m, long long p) {//nCm(mod p)
      |           ^~~~
a.cc:94:11: note: 'long long int bino(long long int, long long int, long long int)' previously defined here
   94 | long long bino(long long n, long long m, long long p) {//nCm(mod p)
      |           ^~~~
a.cc:367:8: error: redefinition of 'struct modint'
  367 | struct modint {
      |        ^~~~~~
a.cc:102:8: note: previous definition of 'struct modint'
  102 | struct modint {
      |        ^~~~~~
a.cc:449:15: error: redefinition of 'std::ostream& operator<<(std::ostream&, const modint&)'
  449 | std::ostream& operator<<(std::ostream &os, const modint &x) {
      |               ^~~~~~~~
a.cc:184:15: note: 'std::ostream& operator<<(std::ostream&, const modint&)' previously defined here
  184 | std::ostream& operator<<(std::ostream &os, const modint &x) {
      |               ^~~~~~~~
a.cc:456:8: error: redefinition of 'struct P'
  456 | struct P {
      |        ^
a.cc:191:8: note: previous definition of 'struct P'
  191 | struct P {
      |        ^
a.cc:468:16: error: redefinition of 'std::vector<modint> li'
  468 | vector<modint> li(220000);
      |                ^~
a.cc:203:16: note: 'std::vector<modint> li' previously declared here
  203 | vector<modint> li(220000);
      |                ^~
a.cc:469:16: error: redefinition of 'std::vector<modint> inv'
  469 | vector<modint> inv(220000);
      |                ^~~
a.cc:204:16: note: 'std::vector<modint> inv' previously declared here
  204 | vector<modint> inv(220000);
      |                ^~~
a.cc:470:16: error: redefinition of 'std::vector<modint> gg'
  470 | vector<modint> gg(220000);
      |                ^~
a.cc:205:16: note: 'std::vector<modint> gg' previously declared here
  205 | vector<modint> gg(220000);
      |                ^~
a.cc:472:8: error: redefinition of 'modint cal(std::vector<int>&)'
  472 | modint cal(vector<int> &da) {
      |        ^~~
a.cc:207:8: note: 'modint cal(std::vector<int>&)' previously defined here
  207 | modint cal(vector<int> &da) {
      |        ^~~
a.cc:483:6: error: redefinition of 'void rec(int, int, int, std::vector<std::vector<P> >&)'
  483 | void rec(int x, int y, int z, vector<vector<P>> &da) {//x->y
      |      ^~~
a.cc:218:6: note: 'void rec(int, int, int, std::vector<std::vector<P> >&)' previously defined here
  218 | void rec(int x, int y, int z, vector<vector<P>> &da) {//x->y
      |      ^~~
a.cc:500:8: error: redefinition of 'modint ans_cal(int, std::vector<std::vector<P> >&)'
  500 | modint ans_cal(int x, vector<vector<P>> &da) {
      |        ^~~~~~~
a.cc:235:8: note: 'modint ans_cal(int, std::vector<std::vector<P> >&)' previously defined here
  235 | modint ans_cal(int x, vector<vector<P>> &da) {
      |        ^~~~~~~
a.cc:508:5: error: redefinition of 'int main()'
  508 | int main() {
      |     ^~~~
a.cc:243:5: note: 'int main()' previously defined here
  243 | int main() {
      |     ^~~~