QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#537124 | #7895. Graph Partitioning 2 | HHAZ | WA | 27ms | 4124kb | C++20 | 3.4kb | 2024-08-29 21:14:31 | 2024-08-29 21:14:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;
typedef pair<ld,ld>pdd;
typedef pair<ll, pair<ll, ll> > plpair;
typedef vector<int> vi;
typedef vector<ll> vl;
#define endl '\n'
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for(ll i = (a); i >= (b); --i)
#define debug(x) cout<<#x<<": "<<x<<endl
#define lowbit(id) id & (-id)
#define fi first
#define sec second
#define lc id<<1
#define rc id<<1|1
#define sz(x) (int)(x).size()
#define all(t) (t).begin(), (t).end()
#define meh {cout<<"NO"<<endl;return;}
#define yay {cout<<"YES"<<endl;return;}
#define vin(v) for(auto&x:v)cin>>x;
#define print(v) for (auto x: v)cout<<x<<' ';cout<<endl;
#define sqrt(x) sqrtl(x)
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 3e3 + 10;
const int mod = 998244353;
struct node{
ll num;
ll val;
};
void solve() {
ll n, k;
cin >> n >> k;
vector<ll>ve[n + 5];
vector<node>dp[n + 5];
ll id[n + 5];
memset(id, -1, sizeof(id));
rep(i, 1, n - 1) {
ll u, v;
cin >> u >> v;
ve[u].push_back(v);
ve[v].push_back(u);
}
rep(i, 1, n) {
dp[i].push_back({1, 1});
}
function<void(ll, ll)> dfs = [&](ll u, ll f) {
for(ll v : ve[u]) {
if(v != f) {
dfs(v, u);
vector<node>temp;
ll tot = 0;
for(node x : dp[u]) {
for(node y : dp[v]) {
ll num;
if(x.num + y.num < k) {
num = x.num + y.num;
if(num && x.num == 0) continue;
if(id[num] == -1) {
id[num] = tot++;
temp.push_back({num, 0});
}
temp[id[num]].val += (x.val * y.val) % mod;
temp[id[num]].val %= mod;
}
else if(x.num + y.num == k) {
num = 0;
if(id[num] == -1) {
id[num] = tot++;
temp.push_back({num, 0});
}
temp[id[num]].val += (x.val * y.val) % mod;
temp[id[num]].val %= mod;
num = k;
if(x.num == 0) continue;
if(id[num] == -1) {
id[num] = tot++;
temp.push_back({num, 0});
}
temp[id[num]].val += (x.val * y.val) % mod;
temp[id[num]].val %= mod;
}
else if(x.num + y.num == k + 1){
num = x.num + y.num - k - 1;
if(id[num] == -1) {
id[num] = tot++;
temp.push_back({num, 0});
}
temp[id[num]].val += (x.val * y.val) % mod;
temp[id[num]].val %= mod;
}
}
}
dp[u] = temp;
rep(i, 0, tot - 1) {
id[temp[i].num] = -1;
}
}
}
};
dfs(1, 0);
ll ans = 0;
for(node d : dp[1]) {
if(d.num == 0) {
ans = d.val;
}
// debug(d.num);
// debug(d.val);
}
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
// cout.flush();
// ofstream outfile("C:\\Users\\86187\\OneDrive\\桌面\\1.txt");
// outfile << "a[1]=0;a[2]=1;";
// ll l = 1e7 + 1;
// rep(i, 3, 1e9) {
// printf("%lld\n", i);
// ll x = (i - 1) * ((a[i - 1] + a[i - 2]) % mod);
// x %= mod;
// if(i == l) {
// outfile << "a[" << i << "]=" << x << ";";
// }
// if(i == l + 1) {
// outfile << "a[" << i << "]=" << x << ";";
// l += 1e7;
// }
// }
while(T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
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: 27ms
memory: 4124kb
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 9 0 1 0 2 0 0 0 4 0 1 0 0 1 0 5 0 0 0 6 1 7 1 1 3 2 0 15 0 1 0 0 0 1 1 0 0 6 60 0 0 24 0 0 1 0 18 1 24 8 3 2 0 1 0 4 0 0 0 0 0 0 0 0 0 1 0 3 1 1 15 0 0 0 1 0 0 0 2 0 1 0 0 1 1 0 0 0 7 0 0 0 10 0 9 0 0 0 2 7 0 2 0 0 2 0 1 0 0 8 0 3 2 0 0 1 0 0 14 0 1 1 0 0 1 1 1 0 0 1 2 1 1 1 0 28 2 1 0 0 0 1 7 8...
result:
wrong answer 3rd lines differ - expected: '112', found: '9'