QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#878883#7895. Graph Partitioning 2duck_pearWA 0ms8648kbC++142.9kb2025-02-01 18:36:242025-02-01 18:36:25

Judging History

This is the latest submission verdict.

  • [2025-02-01 18:36:25]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 8648kb
  • [2025-02-01 18:36:24]
  • Submitted

answer

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define TY int
#define IL inline
#define pb push_back
#define MAXN 100005
#define mod (TY)(998244353)
#define INF (TY)(1e9)
#define For(i,a,b) for(TY i=(a);i<=(b);++i)
#define FOR(i,a,b) for(TY i=(a);i<(b);++i)
#define Rof(i,a,b) for(TY i=(a);i>=(b);--i)
#define ROF(i,a,b) for(TY i=(a);i>(b);--i)
IL TY qr(){
    TY u=0,v=1;char ch=getchar();
    while(ch>'9'||ch<'0')v=(ch=='-'?-1:1),ch=getchar();
    while(ch>='0'&&ch<='9')u=(u*10)+(ch-'0'),ch=getchar();
    return u*v;
}IL void qw(TY now){
    if(now<0){putchar('-');now=-now;}
    if(!now){putchar('0');return;}
    if(now>=10)qw(now/10);putchar(now%10+'0');
}IL void qw(TY now,char ch){qw(now);putchar(ch);}
IL bool ischar(char u){return (u>='a'&&u<='z')||(u>='A'&&u<='Z');}
IL char getc(){
    char u=getchar();
    while(!ischar(u))u=getchar();
    return u;
}IL string qs(){
    string s="";char ch=getchar();
    while(!ischar(ch))ch=getchar();
    while(ischar(ch))s+=ch,ch=getchar();
    return s;
}IL void ws(string s){FOR(i,0,s.size())putchar(s[i]);}
IL TY Pow(TY a,TY b){
    TY ans=1,base=a;
    while(b){
        if(b&1)ans=ans*base%mod;
        base=base*base%mod;b>>=1;
    }return ans;
}IL TY Mod(TY u){return (u>=mod?u-mod:u);}
TY T,n,K,dp[MAXN][355],L[MAXN],R[MAXN],siz[MAXN],tmp[355],ans[MAXN];
vector<TY> e[MAXN];
IL void Pb(TY i,TY j){e[i].pb(j);e[j].pb(i);}
void dfs(TY now,TY fa){
    dp[now][1-L[1]]=1;
    siz[now]=1;
    TY lstans=0;
    FOR(i,0,e[now].size()){
        TY y=e[now][i];
        if(y==fa)continue;
        dfs(y,now);
        TY nxt=siz[now]+siz[y];
        For(j,0,350)tmp[j]=0;
        lstans=1ll*lstans*ans[y]%mod;
        For(j,L[siz[now]],R[siz[now]])if(L[nxt]<=j&&j<=R[nxt]){
            tmp[j-L[nxt]]=1ll*dp[now][j-L[siz[now]]]*ans[y]%mod;
        }For(j,L[siz[now]],R[siz[now]])For(k,L[siz[y]],R[siz[y]]){
            if(L[nxt]<=j+k&&j+k<=R[nxt]){
                tmp[j+k-L[nxt]]=Mod(tmp[j+k-L[nxt]]+1ll*dp[now][j-L[siz[now]]]*dp[y][k-L[siz[y]]]%mod);
            }if(j+k==K||j+k==K+1)lstans=Mod(lstans+1ll*dp[now][j-L[siz[now]]]*dp[y][k-L[siz[y]]]%mod);
        }For(j,0,R[nxt]-L[nxt]+1)dp[now][j]=tmp[j];
        siz[now]+=siz[y];
    }if(K>350)ans[now]=Mod(ans[now]+lstans);
}IL void clear(){
    For(i,1,n){
        siz[i]=L[i]=R[i]=ans[i]=0;
        e[i].clear();
        For(j,0,350)dp[i][j]=0;
    }
}int main(){
    T=qr();while(T--){
        n=qr();K=qr();
        FOR(i,1,n){
            TY u=qr(),v=qr();
            Pb(u,v);
        }For(i,1,n){
            if(K<=350)L[i]=0,R[i]=K+1;
            else if(i<K+1)L[i]=R[i]=i;
            else{
                TY lst=i%K,need=i/K;
                if(need<=lst)L[i]=lst-need,R[i]=lst;
                else L[i]=0,R[i]=350;
            }
        }dfs(1,0);
        qw(ans[1],'\n');
        clear();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 8648kb

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:

0
0

result:

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