Language: C++

#![allow(unused_imports)]
use std::cmp::*;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
   input! {
      n: usize,
      ab: [(usize, usize); n-1]
   }
   comb_init(n);
   let mut rer = Rerooting::new(n, &DP::new());
   ab.iter().for_each(|(a,b)|
      rer.add_edge(a - 1, b - 1)
   );
   rer.init();
   for a in rer.ans {
      println!("{}", a.dp);
   }
}

#[derive(Copy, Clone)]
struct DP {
   dp: Mint,
   t: usize,
}

impl DP {
   fn new() -> Self {
      DP{dp:Mint::from(1), t:0}
   }
}

impl AddRoot for DP {
   fn add_root(&self) -> Self {
      DP {
         dp: self.dp,
         t: self.t + 1,
      }
   }
}

impl Add for DP {
   type Output = Self;

   fn add(self, rhs: Self) -> Self::Output {
      DP {
         dp: self.dp * rhs.dp * comb(self.t + rhs.t, self.t),
         t: self.t + rhs.t,
      }
   }
}

use std::ops::{Add, AddAssign};
trait AddRoot {
   fn add_root(&self) -> Self;
}

struct Rerooting<T:AddRoot + Add<Output = T> + Clone + Copy> {
   to: Vec<Vec<usize>>,
   dp: Vec<Vec<T>>,
   ans: Vec<T>,
   dp0: T,
}

impl<T: Add<Output = T> + AddRoot + Clone + Copy> Rerooting<T> {
   fn new(n: usize, dp0: &T) -> Self {
      Rerooting {
         to: vec![Vec::<usize>::new(); n],
         dp: vec![Vec::<T>::new(); n],
         ans: vec![*dp0; n],
         dp0: *dp0,
      }
   }

   fn add_edge(&mut self, u: usize, v: usize) {
      self.to[u].push(v);
      self.to[v].push(u);
   }

   fn init(&mut self) {
      self.dfs(0, None);
      self.bfs(0, self.dp0, None);
   }

   fn dfs(&mut self, v: usize, p: Option<usize>) -> T {
      let mut dp_sum = self.dp0;
      let deg = self.to[v].len();
      self.dp[v] = vec![self.dp0; deg];
      for i in 0..deg {
         let u = self.to[v][i];
         if matches!(p, Some(p) if u == p) {
            continue;
         }
         self.dp[v][i] = self.dfs(u, Some(v));
         dp_sum = dp_sum + self.dp[v][i];
      }
      dp_sum.add_root()
   }

   fn bfs(&mut self, v: usize, dp_p: T, p: Option<usize>) {
      if let Some(p) = p {
         let x = self.to[v].iter().enumerate().find(|&(_, v)| *v == p);
         if let Some((i, _)) = x {
            self.dp[v][i] = dp_p;
         }
      }

      let deg = self.to[v].len();
      let mut dp_sum_l = vec![self.dp0; deg + 1];
      for i in 0..deg {
         dp_sum_l[i + 1] = dp_sum_l[i] + self.dp[v][i];
      }
      let mut dp_sum_r = vec![self.dp0; deg + 1];
      for i in (0..deg).rev() {
         dp_sum_r[i] = dp_sum_r[i + 1] + self.dp[v][i];
      }

      self.ans[v] = dp_sum_l[deg].add_root();

      for i in 0..deg {
         let u = self.to[v][i];
         if matches!(p, Some(p) if p == u) {
            continue;
         }
         self.bfs(u, (dp_sum_l[i] + dp_sum_r[i + 1]).add_root(), Some(v));
      }
   }
}

use std::ops::*;
const MOD: usize = 1000000007;
#[derive(Copy, Clone, Debug)]
pub struct Mint {
   x: usize,
}
impl Mint {
   fn new(x: usize) -> Self { Mint { x: x } }
   fn pow(self, n: usize) -> Self {
      let mut x = Mint::new(1);
      let mut r = self;
      let mut n = n;
      while n > 0 {
         if n & 1 == 1 {
            x *= r;
         }
         r *= r;
         n >>= 1;
      }
      x
   }
   fn inv(self) -> Self { self.pow((MOD - 2) as usize) }
}
impl AddAssign for Mint {
   fn add_assign(&mut self, rhs: Mint) {
      self.x += rhs.x;
      self.x %= MOD;
   }
}
impl Add for Mint {
   type Output = Mint;
   fn add(self, other: Mint) -> Self {
      let mut res = self;
      res += other;
      res
   }
}
impl SubAssign for Mint {
   fn sub_assign(&mut self, rhs: Mint) {
      if self.x < rhs.x {
         self.x += MOD - rhs.x;
      } else {
         self.x -= rhs.x;
      }
   }
}
impl Sub for Mint {
   type Output = Mint;
   fn sub(self, other: Mint) -> Self {
      let mut res = self;
      res -= other;
      res
   }
}
impl MulAssign for Mint {
   fn mul_assign(&mut self, rhs: Mint) {
      self.x *= rhs.x;
      self.x %= MOD;
   }
}
impl Mul for Mint {
   type Output = Mint;
   fn mul(self, other: Mint) -> Self {
      let mut res = self;
      res *= other;
      res
   }
}
impl DivAssign for Mint {
   fn div_assign(&mut self, rhs: Mint) { *self *= rhs.inv(); }
}
impl Div for Mint {
   type Output = Mint;
   fn div(self, other: Mint) -> Self {
      let mut res = self;
      res *= other;
      res
   }
}
use std::fmt;
impl fmt::Display for Mint {
   fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
      write!(f, "{}", self.x)
   }
}
impl From<i64> for Mint {
   fn from(num: i64) -> Self { Mint { x: num as usize } }
}
impl From<i32> for Mint {
   fn from(num: i32) -> Self { Mint { x: num as usize } }
}

static mut MAX_N: usize = MOD;
static mut FACT: Vec<Mint> = Vec::<Mint>::new();
static mut IFACT: Vec<Mint> = Vec::<Mint>::new();
static mut COMB_FLAG: bool = false;
fn comb_init(n: usize) {
   unsafe {
      COMB_FLAG = true;
      MAX_N = n;
      FACT = vec![Mint::new(1); MAX_N + 1];
      IFACT = vec![Mint::new(1); MAX_N + 1];
      for i in 1..=MAX_N {
         FACT[i] = FACT[i - 1] * Mint::from(i as i64);
      }
      IFACT[MAX_N] = FACT[MAX_N as usize].inv();
      for i in (1..=MAX_N).rev() {
         IFACT[i - 1] = IFACT[i] * Mint::from(i as i64);
      }
   }
}
fn comb_check(n: usize, r: usize) -> bool { unsafe { !(n > MAX_N || r > n) } }
fn comb(n: usize, r: usize) -> Mint {
   unsafe {
      if !COMB_FLAG {
         panic!("FACT is not init");
      }
   }
   if !comb_check(n, r) {
      Mint::from(0)
   } else {
      unsafe { FACT[n] * IFACT[r] * IFACT[n - r] }
   }
}


Compiler output:
a.cc:1:2: error: invalid preprocessing directive #!
    1 | #![allow(unused_imports)]
      |  ^
a.cc:40:10: error: too many decimal points in number
   40 |         (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
      |          ^~~~~~~
a.cc:72:2: error: invalid preprocessing directive #[
   72 | #[derive(Copy, Clone)]
      |  ^
a.cc:140:16: error: too many decimal points in number
  140 |       for i in 0..deg {
      |                ^~~~~~
a.cc:161:16: error: too many decimal points in number
  161 |       for i in 0..deg {
      |                ^~~~~~
a.cc:165:17: error: too many decimal points in number
  165 |       for i in (0..deg).rev() {
      |                 ^~~~~~
a.cc:171:16: error: too many decimal points in number
  171 |       for i in 0..deg {
      |                ^~~~~~
a.cc:183:2: error: invalid preprocessing directive #[
  183 | #[derive(Copy, Clone, Debug)]
      |  ^
a.cc:262:41: warning: missing terminating ' character
  262 |    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
      |                                         ^
a.cc:262:41: error: missing terminating ' character
  262 |    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
      |                                         ^~~~~~~~~~~~~~~~~~~~~
a.cc:283:16: error: too many decimal points in number
  283 |       for i in 1..=MAX_N {
      |                ^~~
a.cc:287:17: error: too many decimal points in number
  287 |       for i in (1..=MAX_N).rev() {
      |                 ^~~
a.cc:2:1: error: 'use' does not name a type
    2 | use std::cmp::*;
      | ^~~
a.cc:3:1: error: 'macro_rules' does not name a type
    3 | macro_rules! input {
      | ^~~~~~~~~~~
a.cc:24:1: error: 'macro_rules' does not name a type
   24 | macro_rules! input_inner {
      | ^~~~~~~~~~~
a.cc:34:1: error: 'macro_rules' does not name a type
   34 | macro_rules! read_value {
      | ^~~~~~~~~~~
a.cc:56:1: error: 'fn' does not name a type
   56 | fn main() {
      | ^~
a.cc:74:4: error: 'dp' does not name a type; did you mean 'DP'?
   74 |    dp: Mint,
      |    ^~
      |    DP
a.cc:78:6: error: expected initializer before 'DP'
   78 | impl DP {
      |      ^~
a.cc:84:1: error: 'impl' does not name a type
   84 | impl AddRoot for DP {
      | ^~~~
a.cc:93:1: error: 'impl' does not name a type
   93 | impl Add for DP {
      | ^~~~
a.cc:104:1: error: 'use' does not name a type
  104 | use std::ops::{Add, AddAssign};
      | ^~~
a.cc:105:1: error: 'trait' does not name a type
  105 | trait AddRoot {
      | ^~~~~
a.cc:109:8: error: 'Rerooting' is not a class template
  109 | struct Rerooting<T:AddRoot + Add<Output = T> + Clone + Copy> {
      |        ^~~~~~~~~
a.cc:109:18: error: 'T' was not declared in this scope
  109 | struct Rerooting<T:AddRoot + Add<Output = T> + Clone + Copy> {
      |                  ^
a.cc:110:4: error: 'to' does not name a type
  110 |    to: Vec<Vec<usize>>,
      |    ^~
a.cc:116:5: error: expected initializer before '<' token
  116 | impl<T: Add<Output = T> + AddRoot + Clone + Copy> Rerooting<T> {
      |     ^
a.cc:181:1: error: 'use' does not name a type
  181 | use std::ops::*;
      | ^~~
a.cc:182:10: error: found ':' in nested-name-specifier, expected '::'
  182 | const MOD: usize = 1000000007;
      |          ^
      |          ::
a.cc:182:7: error: 'MOD' does not name a type
  182 | const MOD: usize = 1000000007;
      |       ^~~
a.cc:184:1: error: 'pub' does not name a type
  184 | pub struct Mint {
      | ^~~
a.cc:187:1: error: 'impl' does not name a type
  187 | impl Mint {
      | ^~~~
a.cc:204:1: error: 'impl' does not name a type
  204 | impl AddAssign for Mint {
      | ^~~~
a.cc:210:1: error: 'impl' does not name a type
  210 | impl Add for Mint {
      | ^~~~
a.cc:218:1: error: 'impl' does not name a type
  218 | impl SubAssign for Mint {
      | ^~~~
a.cc:227:1: error: 'impl' does not name a type
  227 | impl Sub for Mint {
      | ^~~~
a.cc:235:1: error: 'impl' does not name a type
  235 | impl MulAssign for Mint {
      | ^~~~
a.cc:241:1: error: 'impl' does not name a type
  241 | impl Mul for Mint {
      | ^~~~
a.cc:249:1: error: 'impl' does not name a type
  249 | impl DivAssign for Mint {
      | ^~~~
a.cc:252:1: error: 'impl' does not name a type
  252 | impl Div for Mint {
      | ^~~~
a.cc:260:1: error: 'use' does not name a type
  260 | use std::fmt;
      | ^~~
a.cc:261:1: error: 'impl' does not name a type
  261 | impl fmt::Display for Mint {
      | ^~~~
a.cc:265:1: error: expected declaration before '}' token
  265 | }
      | ^
a.cc:266:1: error: 'impl' does not name a type
  266 | impl From<i64> for Mint {
      | ^~~~
a.cc:269:1: error: 'impl' does not name a type
  269 | impl From<i32> for Mint {
      | ^~~~
a.cc:273:8: error: 'mut' does not name a type
  273 | static mut MAX_N: usize = MOD;
      |        ^~~
a.cc:274:8: error: 'mut' does not name a type
  274 | static mut FACT: Vec<Mint> = Vec::<Mint>::new();
      |        ^~~
a.cc:275:8: error: 'mut' does not name a type
  275 | static mut IFACT: Vec<Mint> = Vec::<Mint>::new();
      |        ^~~
a.cc:276:8: error: 'mut' does not name a type
  276 | static mut COMB_FLAG: bool = false;
      |        ^~~
a.cc:277:1: error: 'fn' does not name a type
  277 | fn comb_init(n: usize) {
      | ^~
a.cc:292:1: error: 'fn' does not name a type
  292 | fn comb_check(n: usize, r: usize) -> bool { unsafe { !(n > MAX_N || r > n) } }
      | ^~
a.cc:293:1: error: 'fn' does not name a type
  293 | fn comb(n: usize, r: usize) -> Mint {
      | ^~