QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#300006#7895. Graph Partitioning 2ucup-team870#WA 14ms14040kbC++142.1kb2024-01-07 16:08:112024-01-07 16:08:12

Judging History

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

  • [2024-01-07 16:08:12]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:14040kb
  • [2024-01-07 16:08:11]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,l,r) for(int i=l; i<=r; i++)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
const int N=1e5+5,mo=998244353;
vector<int> v[N];
//15:15-
int n,k;
typedef pair<int,int> pi;
pi dp[N][655]; int cnt[N];
bool vis[N]; int qu[N],ql; ll w[N];
void add(int x,int y,int z){
    dp[x][++cnt[x]]={y,z};
}
void dfs(int x,int fa){
    for(auto y:v[x]) if (y!=fa){
        dfs(y,x);
    }
    //init
    add(x,1,1);
    //merge
    for(auto y:v[x]) if (y!=fa){
        For(i,1,cnt[x])
            For(j,1,cnt[y]){
                auto [fx,wx]=dp[x][i];
                auto [fy,wy]=dp[y][j]; //cout<<' '<<i<<' '<<j<<'#'<<fx<<' '<<fy<<endl;
                if (fx+fy>k+1) continue;
                if (!vis[fx+fy]) vis[fx+fy]=1,qu[++ql]=fx+fy;
                w[fx+fy]=(1ll*wx*wy+w[fx+fy])%mo;
            }
        //give and clear
        sort(qu+1,qu+1+ql);
        cnt[x]=0;
        For(i,1,ql){
            int tmp=qu[i];
            add(x,tmp,w[tmp]);
            vis[tmp]=w[tmp]=0;
        }
        ql=0;
    }
    //pr
    // printf("#%d\n",x);
    // For(i,1,cnt[x]){
    //     printf("%d %d\n",dp[x][i].first,dp[x][i].second);
    // }
    //cal 0
    ll v0=0;
    For(i,1,cnt[x]){
        auto [fx,wx]=dp[x][i];
        if (fx>=k) v0+=wx;
    }
    //move
if (v0){
    for(int i=cnt[x]+1;i>=2;--i) dp[x][i]=dp[x][i-1];    
dp[x][1]={0,v0%mo}; ++cnt[x];
    if (dp[x][cnt[x]].first>=k+1) --cnt[x];}
    //print
    // printf("#%d\n",x);
    // For(i,1,cnt[x]){
    //     printf("%d %d\n",dp[x][i].first,dp[x][i].second);
    // }
}
int main(){
    IOS
    int _; cin>>_;
    while(_--){
        cin>>n>>k;
        For(i,1,n-1){
            int x,y; cin>>x>>y;
            v[x].push_back(y),v[y].push_back(x);
        }
        dfs(1,0);
        cout<<dp[1][1].second<<'\n';
        //clear
        For(i,1,n) v[i].clear(),cnt[i]=0;
    }
    return 0;
}
/*
4
4 1
1 2 1 3 2 4
3 1
1 2 1 3

8 2
1 2
3 1
4 6
3 5
2 4
8 5
5 7

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: 1ms
memory: 7528kb

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: 14ms
memory: 14040kb

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:

1
3
112
1
1
1
1
1
1
1
1
1
1
1
1
1
1
140
1
2
1
814
1
6
1
1
2
2
1
612
1
1
1
1
1
1
1
1
1
121
4536
1
1
1718
1
1
1
1
444
1
1908
1813
3
74
1
1
1
46
1
1
1
1
1
1
1
1
1
1
1
1
1
1
239
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
48
1
2
1
1
2
1
364
1
206
1
1
76
1
1
1
1
2
1
1
2
1
1
1
1
1
4
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

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