QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#581516#7895. Graph Partitioning 2gggggggWA 0ms12164kbC++141.3kb2024-09-22 13:11:212024-09-22 13:11:22

Judging History

你现在查看的是最新测评结果

  • [2024-09-22 13:11:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:12164kb
  • [2024-09-22 13:11:21]
  • 提交

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(g[u].count(k)||g[u].count(k+1)){
        if(!g[u].count(0)) g[u][0]=(++st[u]);
        if(g[u].count(k)) Inc(dp[u][g[u][0]],dp[u][g[u][k]]);
        if(g[u].count(k+1)) 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]]);
}
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: 0
Wrong Answer
time: 0ms
memory: 12164kb

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
2

result:

wrong answer 2nd lines differ - expected: '1', found: '2'