QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#709002 | #7895. Graph Partitioning 2 | louhao088 | WA | 12ms | 4032kb | C++23 | 1.4kb | 2024-11-04 10:41:22 | 2024-11-04 10:41:22 |
Judging History
answer
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define lowbit(i) (i&(-i))
#define fi first
#define se second
#define pi pair<int,int>
const int mod=998244353,maxn=2e5+5,M=100005;
inline int read(){
char ch=getchar();int x=0;bool f=0;
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
if(f==1)x=-x;return x;
}
int n,k,T,x,y;
int vis[maxn],s[maxn];
vector<int>e[maxn],tmp;
vector<pi>f[maxn];
void dfs(int x,int fa){
f[x].pb({1,1});
for(auto i:e[x])if(i^fa){
dfs(i,x);tmp.clear();
for(auto t:f[x]){
for(auto j:f[i]){
if(!t.se||!j.se||t.fi+j.fi>k+1)continue;
int z=t.fi+j.fi;
if(!vis[z])vis[z]=1,tmp.pb(z);
s[z]=(s[z]+t.se*j.se)%mod;
}
}f[x].clear();
for(auto i:tmp){f[x].pb({i,s[i]});vis[i]=s[i]=0;}
}
int p=0;
for(auto i:f[x])if(i.fi==k||i.fi==k+1)p=p+i.se;
p%=mod;f[x].pb({0,p});
//for(auto i:f[x]){cout<<x<<" "<<i.fi<<" "<<i.se<<endl;}
}
void solve(){
n=read();k=read();
for(int i=1;i<=n;i++)f[i].clear(),e[i].clear();
for(int i=1;i<n;i++)
x=read(),y=read(),e[x].pb(y),e[y].pb(x);
dfs(1,0);
cout<<f[1][f[1].size()-1].se<<endl;
}
signed main(){
T=read();
while(T--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
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: 12ms
memory: 4032kb
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 1 0 0 0 1 0 1 0 0 1 0 140 0 0 0 814 1 6 1 1 2 2 0 612 0 1 0 0 0 1 1 0 0 121 4536 0 0 1718 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 1 1 1 239 0 0 0 1 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0 0 0 48 0 2 0 0 0 1 364 0 206 0 0 76 0 1 0 0 2 0 1 2 0 0 1 0 0 4 0 1 1 0 0 1 1 1 0 0 1 1 ...
result:
wrong answer 5004th lines differ - expected: '224400650', found: '160788449'