Submission #45747541


Source Code Expand

// LUOGU_RID: 125305561
#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> inline void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 110, MOD = 998244353;
int n, k, f[N][N][N], sz[N], g[N][N], ans;
vector <int> v[N];
inline void add(int &x, ll y) { x = (x + y) % MOD; }
int fac[N], ifac[N], inv[N];
inline void binom(int x) {
	fac[0] = ifac[0] = inv[1] = 1;
	F(i, 2, x) inv[i] = (ll) (MOD - MOD / i) * inv[MOD % i] % MOD;
	F(i, 1, x) fac[i] = (ll) fac[i - 1] * i % MOD, ifac[i] = (ll) ifac[i - 1] * inv[i] % MOD;
}
inline int C(int x, int y) { return x < y || y < 0 ? 0 : (ll) fac[x] * ifac[y] % MOD * ifac[x - y] % MOD; }
void dfs(int x, int fa) {
	f[x][sz[x] = 1][0] = 1;
	for (int i: v[x])
		if (i != fa) {
			dfs(i, x);
			ms(g, 0);
			F(aa, 1, sz[x])
				F(ab, 0, sz[x] - aa)
					if (f[x][aa][ab]) {
						F(ba, 1, sz[i])
							F(bb, 0, sz[i] - ba)
								add(g[aa + ba][ab + bb], (ll) f[x][aa][ab] * f[i][ba][bb]);
						add(g[aa][ab + 1], f[x][aa][ab]);
					}
			sz[x] += sz[i];
			F(a, 1, sz[x])
				F(b, 0, sz[x] - a)
					f[x][a][b] = g[a][b];
		}
	// F(a, 1, sz[x])
	// 	F(b, 0, sz[x] - a)
	// 		if (f[x][a][b]) cout << x << " " << a << " " << b << " " << f[x][a][b] << endl;
	F(a, k + 1, sz[x])
		F(b, 0, sz[x] - a) {
			int bb = b + !!fa;
			// cout << x << "~ " << a << " " << b << " " << f[x][a][b] << endl;
			// cout << " -> " << bb << " " << C(a + bb, a) << " " << a + bb << endl;
			add(ans, (ll) fac[a] * fac[bb] % MOD * ifac[a + bb] % MOD * f[x][a][b]);
			// cout << fac[a] * fac[bb] << " " << fac[a + bb] << endl;
			// cout << ans << endl;
		}
}
signed main() {
	read(n), read(k);
	binom(n);
	F(i, 2, n) {
		int x, y; read(x), read(y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1, 0);
	cout << ans;
	return 0;
}

Submission Info

Submission Time
Task E - Random Isolation
User ast123
Language C++ 20 (gcc 12.2)
Score 700
Code Size 2332 Byte
Status AC
Exec Time 3 ms
Memory 5628 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 52
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_rand_01.txt, 01_rand_02.txt, 01_rand_03.txt, 01_rand_04.txt, 01_rand_05.txt, 01_rand_06.txt, 01_rand_07.txt, 01_rand_08.txt, 01_rand_09.txt, 01_rand_10.txt, 01_rand_11.txt, 01_rand_12.txt, 01_rand_13.txt, 01_rand_14.txt, 01_rand_15.txt, 01_rand_16.txt, 01_rand_17.txt, 01_rand_18.txt, 01_rand_19.txt, 01_rand_20.txt, 02_line_01.txt, 02_line_02.txt, 02_line_03.txt, 03_star_01.txt, 03_star_02.txt, 03_star_03.txt, 04_caterpillar_01.txt, 04_caterpillar_02.txt, 04_caterpillar_03.txt, 05_worst_01.txt, 05_worst_02.txt, 05_worst_03.txt, 05_worst_04.txt, 05_worst_05.txt, 05_worst_06.txt, 05_worst_07.txt, 05_worst_08.txt, 05_worst_09.txt, 05_worst_10.txt, 05_worst_11.txt, 05_worst_12.txt, 05_worst_13.txt, 05_worst_14.txt, 06_handmade_01.txt, 06_handmade_02.txt, 06_handmade_03.txt, 06_handmade_04.txt, 06_handmade_05.txt, 06_handmade_06.txt, 06_handmade_07.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3552 KiB
00_sample_02.txt AC 1 ms 3620 KiB
01_rand_01.txt AC 3 ms 4144 KiB
01_rand_02.txt AC 2 ms 4164 KiB
01_rand_03.txt AC 2 ms 4156 KiB
01_rand_04.txt AC 2 ms 4468 KiB
01_rand_05.txt AC 2 ms 4296 KiB
01_rand_06.txt AC 3 ms 4580 KiB
01_rand_07.txt AC 2 ms 5032 KiB
01_rand_08.txt AC 2 ms 4584 KiB
01_rand_09.txt AC 2 ms 4688 KiB
01_rand_10.txt AC 3 ms 4548 KiB
01_rand_11.txt AC 2 ms 4152 KiB
01_rand_12.txt AC 2 ms 4116 KiB
01_rand_13.txt AC 2 ms 4188 KiB
01_rand_14.txt AC 2 ms 4100 KiB
01_rand_15.txt AC 2 ms 4312 KiB
01_rand_16.txt AC 2 ms 4636 KiB
01_rand_17.txt AC 2 ms 4448 KiB
01_rand_18.txt AC 2 ms 4780 KiB
01_rand_19.txt AC 2 ms 4512 KiB
01_rand_20.txt AC 2 ms 4484 KiB
02_line_01.txt AC 2 ms 5416 KiB
02_line_02.txt AC 2 ms 5628 KiB
02_line_03.txt AC 1 ms 4148 KiB
03_star_01.txt AC 2 ms 4020 KiB
03_star_02.txt AC 2 ms 3864 KiB
03_star_03.txt AC 1 ms 4036 KiB
04_caterpillar_01.txt AC 2 ms 4800 KiB
04_caterpillar_02.txt AC 2 ms 4188 KiB
04_caterpillar_03.txt AC 2 ms 4400 KiB
05_worst_01.txt AC 2 ms 4592 KiB
05_worst_02.txt AC 2 ms 4484 KiB
05_worst_03.txt AC 2 ms 4672 KiB
05_worst_04.txt AC 2 ms 4488 KiB
05_worst_05.txt AC 2 ms 4568 KiB
05_worst_06.txt AC 2 ms 4512 KiB
05_worst_07.txt AC 2 ms 4900 KiB
05_worst_08.txt AC 2 ms 4312 KiB
05_worst_09.txt AC 2 ms 4032 KiB
05_worst_10.txt AC 2 ms 4228 KiB
05_worst_11.txt AC 2 ms 4064 KiB
05_worst_12.txt AC 2 ms 4320 KiB
05_worst_13.txt AC 2 ms 4248 KiB
05_worst_14.txt AC 2 ms 4204 KiB
06_handmade_01.txt AC 1 ms 3548 KiB
06_handmade_02.txt AC 2 ms 4756 KiB
06_handmade_03.txt AC 2 ms 4344 KiB
06_handmade_04.txt AC 2 ms 4316 KiB
06_handmade_05.txt AC 2 ms 4224 KiB
06_handmade_06.txt AC 2 ms 4612 KiB
06_handmade_07.txt AC 2 ms 4688 KiB