const MOD: usize = 1e9 as usize + 7; fn power(base: usize, times: usize) -> usize { if times == 0 { return 1usize; } if times == 1 { return base; } let temp = power(base, times/2); temp * temp % MOD * power(base, times%2) % MOD } fn dfs(cur: usize, prev: usize, paths: &Vec>, depths: &mut Vec) { for &v in paths[cur].iter() { if v == prev { continue; } depths[v] = depths[cur] + 1; dfs(v, cur, paths, depths); } } fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut paths = vec![vec![]; n]; for _ in 0..n-1 { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let a = temp[0]-1; let b = temp[1]-1; paths[a].push(b); paths[b].push(a); } let mut depths = vec![0usize; n]; dfs(0, 0, &paths, &mut depths); let total_pattern = (1..=n).fold(1usize, |x, y| x * y % MOD); let limit = depths.iter().max().unwrap()+2; let mut mods = vec![0usize; limit+1]; for i in 1..=limit { mods[i] = power(i, MOD-2); } let result = total_pattern * ((0..n).map(|i| mods[depths[i]+1]).sum::() % MOD) % MOD; println!("{}", result); }