#include using namespace std; using Int = long long; const char newl = '\n'; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a void drop(const T &x){cout< vector read(size_t n){ vector ts(n); for(size_t i=0;i>ts[i]; return ts; } template struct Mint{ static constexpr T mod = MOD; T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0) v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } static Mint add_identity(){return Mint(0);} static Mint mul_identity(){return Mint(1);} Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;} Mint operator-(Mint a) const{return Mint(v)-=a;} Mint operator*(Mint a) const{return Mint(v)*=a;} Mint operator/(Mint a) const{return Mint(v)/=a;} Mint operator-() const{return v?Mint(MOD-v):Mint(v);} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} bool operator <(const Mint a)const{return v constexpr T Mint::mod; template ostream& operator<<(ostream &os,Mint m){os< V compress(V vs){ sort(vs.begin(),vs.end()); vs.erase(unique(vs.begin(),vs.end()),vs.end()); return vs; } template map dict(const vector &vs){ map res; for(int i=0;i<(int)vs.size();i++) res[vs[i]]=i; return res; } map dict(const string &s){ return dict(vector(s.begin(),s.end())); } struct UnionFind{ int num; vector rs,ps; UnionFind(int n):num(n),rs(n,1),ps(n,0){ iota(ps.begin(),ps.end(),0); } int find(int x){ return (x==ps[x]?x:ps[x]=find(ps[x])); } bool same(int x,int y){ return find(x)==find(y); } void unite(int x,int y){ x=find(x);y=find(y); if(x==y) return; if(rs[x]>n>>k; vector as(n),bs(n); for(int i=0;i>as[i]>>bs[i],as[i]--,bs[i]--; using M = Mint; M ans{0}; map, int> cnt; for(int bit=0;bit<(1< vs,deg(n); UnionFind uf(n); for(int i=0;i>i)&1){ uf.unite(as[i],bs[i]); deg[as[i]]++; deg[bs[i]]++; vs.emplace_back(as[i]); vs.emplace_back(bs[i]); } } vs=compress(vs); int valid=true; for(int v:vs) valid&=uf.same(vs[0],v); if(not valid) continue; int x=0,y=0; for(int v:vs){ if(deg[v]==1) x++; if(deg[v]>=2) y++; } cnt[make_pair(x,y)]++; ans+=M(k).pow(x)*(M(1)-M(k)).pow(n-x-y)*M(x+y); } // for(auto[p,c]:cnt) cout<