1 solutions
-
0
/* * __----~~~~~~~~~~~------___ * . . ~~//====...... __--~ ~~ * -. \_|// |||\\ ~~~~~~::::... /~ * ___-==_ _-~o~ \/ ||| \\ _/~~- * __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ * _-~~ .=~ | \\-_ '-~7 /- / || \ / * .~ .~ | \\ -_ / /- / || \ / * / ____ / | \\ ~-_/ /|- _/ .|| \ / * |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ * ' ~-| /| |-~\~~ __--~~ * |-~~-_/ | | ~\_ _-~ /\ * / \ \__ \/~ \__ * _--~ _/ | .-~~____--~-/ ~~==. * ((->/~ '.|||' -_| ~~-/ , . _|| * -_ ~\ ~~---l__i__i__i--~~_/ * _-~-__ ~) \--______________--~~ * //.-~~~-~_--~- |-------~~~~~~~~ * //.-~~~--\ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * 神兽保佑 永无BUG */ /* * @Description: I want to be the weakest vegetable in the world! * @Author: I.Z. */ #include<bits/stdc++.h> using namespace std; #define MOD 998244353 #define int long long #define pii pair<int,int> #define all(v) v.begin(),v.end() #define pb push_back #define REP(i,b,e) for(int i=(b);i<(int)(e);++i) #define over(x) {cout<<(x)<<endl;return;} #define lowbit(x) ((x)&(-(x))) #define cntbit(x) __builtin_popcount(x) #define deal(v) sort(all(v));v.erase(unique(v.begin(),v.end()),v.end()) #define lbound(v,x) lower_bound(all(v),x)-v.begin() mt19937 sd(random_device{}()); int qpow(int a,int b,int m=MOD,int res=1){ a%=m; while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1; return res; } int exgcd(int x,int y,int &a,int &b){ if(y==0){ a=1;b=0; return x; } int d=exgcd(y,x%y,a,b); int z=b; b=a-b*(x/y); a=z; return d; } int _x_,_y_; inline int inverse(int x,int y=MOD){ exgcd(x,y,_x_,_y_); return (_x_+y)%y; } int fac[2000005],inv[2000005]; void init(int n){ fac[0]=inv[0]=1; REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD; inv[n]=qpow(fac[n],MOD-2); for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD; } int binom(int x,int y){ return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD; } int n,m; vector<int>v[100]; int f[55][140000]; int sz[140000]; int g[140000]; vector<pii>h[55]; int f1[140000],f2[140000]; int G,MN; void predfs(int x,int pre){ int mx=0;sz[x]=1; for(auto i:v[x])if(i!=pre){ predfs(i,x); sz[x]+=sz[i]; mx=max(mx,sz[i]); } mx=max(mx,n-sz[x]); if(mx<=MN)G=x,MN=mx; } void dfs(int x,int pre){ vector<int>t; for(auto i:v[x])if(i!=pre){ dfs(i,x); t.pb(i); } if(!t.size()){ REP(i,0,m)f[x][(1<<i)]=1; return; } REP(i,0,m){ //不许有 =i 的,小于 i 的可以取消 for(auto j:t){ REP(l,0,(1<<(m-i-1)))g[l]=0; REP(l,0,(1<<m))if(!((l>>i)&1)){ // cout<<'!'<<j<<' '<<l<<' '<<f[j][l]<<endl; g[l>>(i+1)]+=f[j][l]; } vector<pii>().swap(h[j]); REP(l,0,(1<<(m-i-1))){ g[l]%=MOD; // cout<<l<<' '<<g[l]<<' '; if(g[l])h[j].pb({l,g[l]}); } // cout<<endl; } // cout<<endl; int M=m-i-1; priority_queue<pii,vector<pii>,greater<pii>>pq; int fail=0; for(auto j:t)if(h[j].size())pq.push({h[j].size(),j}); else fail=1; // cout<<pq.size()<<endl; while(pq.size()>1&&!fail){ int x=pq.top().second;pq.pop(); int y=pq.top().second;pq.pop(); REP(j,0,(1<<M))f1[j]=f2[j]=0; for(auto [j,l]:h[y])f1[j]=l; for(auto [j,l]:h[x]){ int R=(1<<M)-1;R^=j; (f2[j]+=l*f1[0])%=MOD; // cout<<'?'<<j<<' '<<0<<' '<<l*f1[0]<<endl; for(int p=R;p;p=(p-1)&R){ // cout<<'?'<<j<<' '<<p<<' '<<l*f1[p]<<endl; (f2[p|j]+=l*f1[p])%=MOD; } } vector<pii>().swap(h[x]); REP(j,0,(1<<M))if(f2[j])h[x].pb({j,f2[j]}); if(h[x].size())pq.push({h[x].size(),x}); else fail=1; } if(fail)continue; if(pq.size()){ int X=pq.top().second; for(auto [j,l]:h[X])(f[x][(j*2+1)<<i]+=l)%=MOD;//,cout<<'!'<<j<<' '<<l<<endl; } } } void Main() { cin>>n>>m; REP(i,1,n){ int x,y; cin>>x>>y; --x,--y; v[x].pb(y);v[y].pb(x); } MN=n; predfs(0,-1);dfs(G,-1); // cout<<G<<endl; // REP(i,0,n){ // REP(j,0,(1<<m))cout<<f[i][j]<<' '; // cout<<endl; // } int ans=0; REP(i,0,(1<<m))ans+=f[G][i]; over(ans%MOD) } void TC() { int tc=1; while(tc--){ Main(); cout.flush(); } } signed main() { freopen("dac.in","r",stdin); freopen("dac.out","w",stdout); return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0; } /* 1. CLEAR the arrays (ESPECIALLY multitests) 2. DELETE useless output */
- 1
Information
- ID
- 3103
- Time
- 3000ms
- Memory
- 512MiB
- Difficulty
- 10
- Tags
- (None)
- # Submissions
- 1
- Accepted
- 1
- Uploaded By