QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#581501 | #7895. Graph Partitioning 2 | ggggggg | WA | 40ms | 14976kb | C++14 | 1.3kb | 2024-09-22 13:07:19 | 2024-09-22 13:07:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=100005,P=998244353;
int n,k,sz[N],dp[N][505],f[505],st[N];
vector<int> G[N];
unordered_map<int,int> g[N],gg;
void Inc(int&x,int y){
if((x+=y)>=P) x-=P;
}
void dfs(int u,int fa){
sz[u]=1,g[u][1]=(++st[u]),dp[u][1]=1;
for(auto v:G[u]) if(v^fa){
dfs(v,u),gg.clear();
int st1=0;
for(auto i:g[v]) for(auto j:g[u]){
int x=i.first,y=j.first;
if(x+y>k+1||dp[u][j.second]==0||dp[v][i.second]==0) continue;
if(!gg.count(x+y)) gg[x+y]=(++st1);
Inc(f[gg[x+y]],1ll*dp[u][j.second]*dp[v][i.second]%P);
}
for(int i=1;i<=st1;i++) dp[u][i]=f[i],f[i]=0;
sz[u]+=sz[v],st[u]=st1,g[u]=gg;
}
if(dp[u][g[u][k]]||dp[u][g[u][k+1]]){
if(!g[u].count(0)) g[u][0]=(++st[u]);
Inc(dp[u][g[u][0]],dp[u][g[u][k]]);
Inc(dp[u][g[u][0]],dp[u][g[u][k+1]]);
}
}
void solve(){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++) G[i].clear(),g[i].clear(),st[i]=0;
for(int i=2,x,y;i<=n;i++) scanf("%d%d",&x,&y),G[x].push_back(y),G[y].push_back(x);
dfs(1,0);
printf("%d\n",dp[1][g[1][0]]);
for(int i=1;i<=n;i++) for(int j=1;j<=st[i];j++) dp[i][j]=0;
}
int main(){
int T;
scanf("%d",&T);
while(T--) solve();
}
/*
1
4 3
1 2
1 3
2 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 14976kb
input:
2 8 2 1 2 3 1 4 6 3 5 2 4 8 5 5 7 4 3 1 2 1 3 2 4
output:
2 1
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 40ms
memory: 14928kb
input:
5550 13 4 10 3 9 1 10 8 3 11 8 5 10 7 9 6 13 5 9 7 2 7 5 12 4 8 8 2 4 1 3 4 7 8 2 5 6 7 4 8 2 3 11 1 11 10 1 4 9 10 8 4 3 6 5 7 6 1 10 2 11 7 11 1 17 2 14 16 13 15 17 3 15 11 1 6 13 2 13 17 4 8 14 10 8 14 14 5 9 12 14 2 12 17 17 6 15 7 14 6 2 14 2 13 2 4 8 4 3 11 7 3 14 1 11 9 13 3 5 10 6 8 3 10 14 ...
output:
0 3 112 0 1 0 2 0 0 0 3 0 1 0 0 1 0 140 0 0 0 814 1 9 1 1 3 2 0 612 0 1 0 0 0 1 1 0 0 121 4536 0 0 3016 0 0 1 0 444 1 1908 1813 3 74 0 1 0 46 0 0 0 0 0 0 0 0 0 1 0 2 1 1 239 0 0 0 1 0 0 0 2 0 1 0 0 1 1 0 0 0 3 0 0 0 128 0 4 0 0 0 1 364 0 206 0 0 76 0 1 0 0 6 0 1 2 0 0 1 0 0 8 0 1 1 0 0 2 1 1 0 0 1 1...
result:
wrong answer 7th lines differ - expected: '1', found: '2'