#![allow(unused_imports,non_snake_case,dead_code)] use std::{cmp::Reverse as Rev,ops::Range,collections::*,iter::*}; use proconio::{marker::*,*}; #[fastout] fn main(){ input!{ n:usize, c:usize, es:[(Usize1,Usize1);n-1], } let mut g=vec![vec![];n]; for &(u,v) in &es{ g[u].push(v); g[v].push(u); } let size=(0..n).map(|i|g[i].len() as u64).collect::>(); let pre=Pre::::new(2*n+500); let get=|c:M,n:u64|->M{ let mut ans=c.pow(n); for k in n/2+1..n{ ans-=c*pre.choose(n as usize,k as usize)*(c-1).pow(n-k); } ans }; let solve=|c:usize|->M{ let c=M::new(c); let mut ans=get(c,size[0]); let c_inv=c.inv(); for i in 1..g.len(){ ans*=get(c,size[i])*c_inv; } ans }; let mut ans=M::new(0); for i in 0..c{ // i色使ってない色を確定する let sign=if i%2==0{ M::new(1) } else{ -M::new(1) }; ans+=solve(c-i)*pre.choose(c,i)*sign; } println!("{ans}"); } type M=ModInt998244353; type ModInt998244353=ModInt<998244353>; type ModInt1000000007=ModInt<1000000007>; #[derive(Clone,Copy,PartialEq,Eq,Default,Hash)] struct ModInt(u32); impl ModIntBase for ModInt{ fn modulus()->u32{ MOD } fn val(self)->u32{ self.0 } fn new(v:impl RemU32)->Self{ Self(v.rem_u32(MOD)) } fn inv(self)->Self{ assert!(self.0!=0); let (mut a,mut b)=(self.0 as i64,MOD as i64); let (mut u,mut v)=(1,0); while b!=0{ let t=a/b; (a,b)=(b,a-t*b); (u,v)=(v,u-t*v); } assert!(a==1); if u<0{ u+=MOD as i64; } Self(u as u32) } fn pow(self,mut k:u64)->Self{ let mut pow2=self; let mut ret=Self(1); while k>0{ if k&1==1{ ret*=pow2; } pow2*=pow2; k>>=1; } ret } } impl std::fmt::Display for ModInt{ fn fmt(&self,f:&mut std::fmt::Formatter)->std::fmt::Result{ write!(f,"{}",self.0) } } impl std::fmt::Debug for ModInt{ fn fmt(&self,f:&mut std::fmt::Formatter)->std::fmt::Result{ write!(f,"{}",self.0) } } impl std::ops::Add for ModInt{ type Output=Self; fn add(self,a:Self)->Self{ let mut new=self.0+a.0; if MOD<=new{ new-=MOD; } Self(new) } } impl std::ops::Sub for ModInt{ type Output=Self; fn sub(self,a:Self)->Self{ let mut new=self.0-a.0; if 0>new as i32{ new+=MOD; } Self(new) } } impl std::ops::Mul for ModInt{ type Output=Self; fn mul(self,a:Self)->Self{ Self((self.0 as u64*a.0 as u64%MOD as u64) as u32) } } impl std::ops::Div for ModInt{ type Output=Self; fn div(self,a:Self)->Self{ self*a.inv() } } impl std::ops::Neg for ModInt{ type Output=Self; fn neg(self)->Self{ if self.0==0{ return self; } Self(MOD-self.0) } } impl std::str::FromStr for ModInt{ type Err=::Err; fn from_str(s:&str)->Result{ let x=s.parse::()?; Ok(Self::new(x)) } } macro_rules! impl_modint_ops{ ($trait:ident,$func:ident,$assign_trait:ident,$assign_func:ident,$op:tt)=>{ impl std::ops::$assign_trait for ModInt{ fn $assign_func(&mut self,a:Self){ *self=*self $op a } } impl std::ops::$trait for ModInt{ type Output=Self; fn $func(self,a:T)->Self{ self $op Self::new(a) } } impl std::ops::$assign_trait for ModInt{ fn $assign_func(&mut self,a:T){ *self=*self $op Self::new(a) } } } } impl_modint_ops!(Add,add,AddAssign,add_assign,+); impl_modint_ops!(Sub,sub,SubAssign,sub_assign,-); impl_modint_ops!(Mul,mul,MulAssign,mul_assign,*); impl_modint_ops!(Div,div,DivAssign,div_assign,/); impl std::iter::Sum for ModInt{ fn sum>(iter:I)->Self{ iter.fold(Self(0),|sum,x|sum+x) } } impl std::iter::Product for ModInt{ fn product>(iter:I)->Self{ iter.fold(Self(1),|prod,x|prod*x) } } trait RemU32{ fn rem_u32(self,m:u32)->u32; } macro_rules! impl_rem_u32{ ($($ty:tt),*)=>{ $( impl RemU32 for $ty{ fn rem_u32(self,m:u32)->u32{ (self as i64).rem_euclid(m as i64) as _ } } )* } } impl_rem_u32!(i32,i64); macro_rules! impl_rem_u32{ ($($ty:tt),*)=>{ $( impl RemU32 for $ty{ fn rem_u32(self,m:u32)->u32{ (self%(m as $ty)) as _ } } )* } } impl_rem_u32!(u32,u64,usize); trait ModIntBase:Default+std::str::FromStr+Copy+Eq+std::hash::Hash+std::fmt::Display+std::fmt::Debug +std::ops::Neg+std::ops::Add+std::ops::Sub +std::ops::Mul+std::ops::Div +std::ops::AddAssign+std::ops::SubAssign+std::ops::MulAssign+std::ops::DivAssign { fn modulus()->u32; fn val(self)->u32; fn new(v:impl RemU32)->Self; fn inv(self)->Self; fn pow(self,k:u64)->Self; } // Modを超える数はpanicする // 注意: // Modは素数 // multi_choose(n,k)を使うときは,fac(n+k-1)まで必要になる struct Pre{ fac:Vec, finv:Vec, } impl Pre{ fn new(n:usize)->Self{ assert!(nM{ self.fac[n] } fn finv(&self,n:usize)->M{ self.finv[n] } fn inv(&self,n:usize)->M{ assert!(n!=0); self.finv[n]*self.fac[n-1] } fn perm(&self,n:usize,k:usize)->M{ if nM{ if nM{ if (n as i64)<0 || (k as i64)<0{ return M::new(0); } if n==0 && k==0{ return M::new(1); } self.choose(n+k-1,k) } }