#include typedef int LL; typedef double dl; #define opt operator #define pb push_back const LL maxn=1e6+9,mod=1e9+7,inf=0x3f3f3f3f; LL Read(){ LL x(0),f(1); char c=getchar(); while(c<'0' || c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0' && c<='9'){ x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar(); }return x*f; } void Chkmin(LL &x,LL y){ if(yx) x=y; } LL add(LL x,LL y){ return x+=y,x>=mod?x-mod:x; } LL dec(LL x,LL y){ return x-=y,x<0?x+mod:x; } LL mul(LL x,LL y){ return 1ll*x*y%mod; } LL Pow(LL base,LL b){ LL ret(1); while(b){ if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1; }return ret; } struct node{ LL to,nxt; }dis[maxn]; LL T,n,m,num; LL head[maxn],g[maxn],f[maxn],deg[maxn],fa[maxn],inv[maxn],dep[maxn]; void Add(LL u,LL v){ dis[++num]=(node){v,head[u]}; head[u]=num; } void Dfs(LL u,LL ff){ for(LL i=head[u];i;i=dis[i].nxt){ LL v(dis[i].to); if(v==ff) continue; fa[v]=u; deg[v]=1; Dfs(v,u); deg[u]++; } } void Dfs1(LL u,LL ff){ dep[u]=dep[ff]+1; for(LL i=head[u];i;i=dis[i].nxt){ LL v(dis[i].to); if(v==ff) continue; f[v]=1ll*f[u]*inv[deg[u]]%mod; if(deg[u]>1) g[v]=1ll*f[u]*(deg[u]-1-(ff!=0))%mod*inv[deg[u]]%mod*inv[deg[u]-1]%mod; g[v]=add(g[v],1ll*g[u]*inv[deg[u]]%mod); Dfs1(v,u); } } int main(){ /*for(LL i=2;i<=30;++i){ for(LL j=1;j