QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#379821 | #7895. Graph Partitioning 2 | definieren | TL | 36ms | 12672kb | C++20 | 3.9kb | 2024-04-06 19:19:15 | 2024-04-06 19:19:15 |
Judging History
answer
//221.2.86.180:9009
#include <bits/stdc++.h>
#define fir first
#define sec second
#ifdef LOCAL
#define dbg(x) cerr << "In Line " << __LINE__ << " the " << #x << " = " << x << '\n';
#define dpi(x, y) cerr << "In Line " << __LINE__ << " the " << #x << " = " << x << " ; " << "the " << #y << " = " << y << '\n';
#define dbgf(fmt, args...) fprintf(stderr, fmt, ##args);
#else
#define dbg(x) void();
#define dpi(x, y) void();
#define dbgf(fmt, args...) void();
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vpii = vector<pii>;
bool Mbe;
constexpr int MOD = 998244353;
template<typename T> T add(T a, T b, T p = MOD) { return (a + b >= p) ? (a + b - p) : (a + b); }
template<typename T> T del(T a, T b, T p = MOD) { return (a - b < 0) ? (a - b + p) : (a - b); }
template<typename T> T mul(T a, T b, T p = MOD) { return 1ll * a * b % p; }
template<typename T> T cadd(T &a, T b, T p = MOD) { return a = add(a, b, p); }
template<typename T> T cdel(T &a, T b, T p = MOD) { return a = del(a, b, p); }
template<typename T> T cmul(T &a, T b, T p = MOD) { return a = mul(a, b, p); }
template<typename T> T cmax(T &a, T b) { return a = max(a, b); }
template<typename T> T cmin(T &a, T b) { return a = min(a, b); }
namespace FastIO {
constexpr int LEN = 1 << 20;
char in[LEN + 1], out[LEN + 1];
char *pin = in, *pout = out, *ein = in, *eout = out + LEN;
char gc() { return pin == ein && (ein = (pin = in) + fread(in, 1, LEN, stdin), ein == in) ? EOF : *pin ++; }
void pc(char c) { pout == eout && (fwrite(out, 1, LEN, stdout), pout = out); (*pout ++) = c; return; }
void Flush() { fwrite(out, 1, pout - out, stdout); pout = out; }
template<typename T> T Read() {
T x = 0; int f = 1; char ch = gc();
while (ch < '0' || ch > '9') f = (ch == '-' ? (~f + 1) : f), ch = gc();
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc();
return x * f;
}
template<typename T> void Write(T x, char c) {
static char stk[40]; int tp = 0;
if (x < 0) pc('-'), x = ~x + 1;
do stk[tp++] = x % 10 + 48, x /= 10; while (x);
while (tp --) pc(stk[tp]); pc(c); return;
}
void Read(char *s) {
char ch = gc();
while (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9'))) ch = gc();
while ((ch != EOF) && ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9'))) *s = ch, s ++, ch = gc();
*s = '\0'; return;
}
void Write(char *s) {
while (*s != '\0') pc(*s), s ++; return;
}
void Puts(char *s) {
Write(s), pc('\n'); return;
}
}
#define getchar FastIO::gc
#define putchar FastIO::pc
#define Flush FastIO::Flush
#define Read FastIO::Read
#define Write FastIO::Write
#define Puts FastIO::Puts
constexpr int MAXN = 1e5 + 5;
int n, k;
vector<int> G[MAXN];
unordered_map<int, int> f[MAXN], g;
void dp(int u, int fa) {
f[u].clear(), f[u][1] = 1;
for (auto v : G[u]) {
if (v == fa) continue;
dp(v, u), g.clear();
if (f[v].count(k))
for (auto [i, x] : f[u])
cadd(g[i], mul(x, f[v][k]));
if (f[v].count(k + 1))
for (auto [i, x] : f[u])
cadd(g[i], mul(x, f[v][k + 1]));
for (auto [i, x] : f[u])
for (auto [j, y] : f[v])
cadd(g[i + j], mul(x, y));
f[u].clear();
for (auto [i, x] : g)
f[u][i] = x;
}
return;
}
void slv() {
n = Read<int>(), k = Read<int>();
for (int i = 1; i < n; i ++) {
int u = Read<int>(), v = Read<int>();
G[u].emplace_back(v), G[v].emplace_back(u);
}
dp(1, 0);
Write(add(f[1][k], f[1][k + 1]), '\n');
return;
}
void clr() {
for (int i = 1; i <= n; i ++)
G[i].clear();
return;
}
bool Med;
int main() {
// int T = 1;
int T = Read<int>();
while (T --) slv(), clr();
Flush();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11584kb
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: 0
Accepted
time: 36ms
memory: 12672kb
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:
ok 5550 lines
Test #3:
score: -100
Time Limit Exceeded
input:
3 99990 259 23374 69108 82204 51691 8142 67119 48537 97966 51333 44408 33147 68485 21698 86824 15746 58746 78761 86975 58449 61819 69001 68714 25787 2257 25378 14067 64899 68906 29853 31359 75920 85420 76072 11728 63836 55505 43671 98920 77281 25176 40936 66517 61029 61440 66908 52300 92101 59742 69...