QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#278677 | #7895. Graph Partitioning 2 | ucup-team956 | WA | 1ms | 3524kb | C++20 | 1.7kb | 2023-12-07 19:10:54 | 2023-12-07 19:10:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define time chrono::system_clock::now().time_since_epoch().count()
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
mt19937_64 rnd(time);
#define maxn 1000005
// #define int long long
int read() {int x;cin>>x;return x;}
const int mod = 998244353;
void solve() {
int n = read(), k = read();
vector<vector<int>>g(n + 1);
for(int i = 1; i < n; i++) {
int aa = read(), bb = read();
g[aa].push_back(bb);
g[bb].push_back(aa);
}
int ok = 1;
vector<gp_hash_table<int,int>>f(n + 1);
// vector f(n + 1, vector(3, 0ll));
// 0:1 1:k + 1 2:sz
vector sz(n + 1, 0ll);
auto dfs = [&](auto dfs, int x, int fa) -> void {
f[x][1] = 1;
for(int i : g[x]) {
if(i == fa) continue;
dfs(dfs, i, x);
gp_hash_table<int,int>ff;
for(auto [key, val] : f[x]) {
if(val == 0) continue;
for(auto [k1, v1] : f[i]) {
if(v1 == 0) continue;
if(k1 + key <= k + 1) {
ff[k1 + key] = (ff[k1 + key] + (1ll * v1 * val)) % mod;
}
if(k1 >= k) {
ff[key] = (ff[key] + 1ll * val * v1) % mod;
}
}
}
f[x] = ff;
}
if(x != 1) f[x].clear();
};
dfs(dfs, 1, 0);
cout << (f[1][k] + f[1][k + 1]) % mod << "\n";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t = read();
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3524kb
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'