QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#820458 | #4540. Counting Stickmen | SGColin | AC ✓ | 564ms | 80964kb | C++20 | 4.1kb | 2024-12-18 21:30:14 | 2024-12-18 21:30:18 |
Judging History
answer
#include <bits/stdc++.h>
//
#define var auto
#define let auto const
#define mid ((l + r) >> 1)
#define loop for (;;)
#define downTo(n) for (int it{n}; it; --it)
#define repeat(n) for (int it{1}, ed{n}; it <= ed; ++it)
typedef long long Int;
typedef long double real;
int i32() {
int a{}, b{}, sgn{};
for (; !isdigit(b); b = getchar()) sgn = b == '-';
for (; +isdigit(b); b = getchar()) a = a * 10 + b - '0';
return sgn ? -a : +a;
}
const int N = 5e5 + 5;
int c23[N];
int c32[N];
int c34[N];
int c35[N];
int c324[N];
int c325[N];
int c344[N];
int c345[N];
int c3244[N];
int c3245[N];
int c3445[N];
int c32445[N];
int c43[N];
int c46[N];
int c436[N];
int c53[N];
int c57[N];
int c537[N];
int c577[N];
int c5377[N];
int c64[N];
int c75[N];
std::vector<int> ch[N];
const int P = 998244353;
inline int sum(int a, int b) { return a + b >= P ? a + b - P : a + b; }
inline int sum(int a, int b, int c) { return sum(sum(a, b), c); }
inline int sum(int a, int b, int c, int d) { return sum(sum(a, b), sum(c, d)); }
inline int sum(int a, int b, int c, int d, int e, int f, int g) { return sum(sum(a, b, c, d), sum(e, f, g)); }
int ans;
void solve(int u, int f) {
c23[u] = 0;
c32[u] = 0;
c34[u] = 0;
c35[u] = 0;
c324[u] = 0;
c325[u] = 0;
c344[u] = 0;
c345[u] = 0;
c3244[u] = 0;
c3245[u] = 0;
c3445[u] = 0;
c32445[u] = 0;
c43[u] = 0;
c46[u] = 0;
c436[u] = 0;
c53[u] = 0;
c57[u] = 0;
c537[u] = 0;
c577[u] = 0;
c5377[u] = 0;
c64[u] = 0;
c75[u] = 0;
for (int v: ch[u])
if (v != f) {
solve(v, u);
Int x23 = c23[u];
Int x32 = c32[u];
Int x34 = c34[u];
Int x35 = c35[u];
Int x324 = c324[u];
Int x325 = c325[u];
Int x344 = c344[u];
Int x345 = c345[u];
Int x3244 = c3244[u];
Int x3245 = c3245[u];
Int x3445 = c3445[u];
Int x32445 = c32445[u];
Int x43 = c43[u];
Int x46 = c46[u];
Int x436 = c436[u];
Int x53 = c53[u];
Int x57 = c57[u];
Int x537 = c537[u];
Int x577 = c577[u];
Int x5377 = c5377[u];
Int x64 = c64[u];
Int x75 = c75[u];
Int y3244 = c3244[v];
Int y3245 = c3245[v];
Int y3445 = c3445[v];
Int y43 = c43[v];
Int y46 = c46[v];
Int y537 = c537[v];
Int y577 = c577[v];
c23[u] = sum(x23, y3445);
c32[u] = sum(x32, 1);
c34[u] = sum(x34, y46);
c35[u] = sum(x35, y577);
c324[u] = sum(x324, x32 * y46 % P, x34);
c325[u] = sum(x325, x32 * y577 % P, x35);
c344[u] = sum(x344, x34 * y46 % P);
c345[u] = sum(x345, x34 * y577 % P, x35 * y46 % P);
c3244[u] = sum(x3244, x324 * y46 % P, x344);
c3245[u] = sum(x3245, x324 * y577 % P, x325 * y46 % P, x345);
c3445[u] = sum(x3445, x344 * y577 % P, x345 * y46 % P);
c32445[u] = sum(x32445, x3244 * y577 % P, x3245 * y46 % P, x3445);
c43[u] = sum(x43, y3245);
c46[u] = sum(x46, 1);
c436[u] = sum(x436, x43, x46 * y3245 % P);
c53[u] = sum(x53, y3244);
c57[u] = sum(x57, 1);
c537[u] = sum(x537, x53, x57 * y3244 % P);
c577[u] = sum(x577, x57);
c5377[u] = sum(x5377, x537, x577 * y3244 % P);
c64[u] = sum(x64, y43);
c75[u] = sum(x75, y537);
}
ans = sum(ans, c23[u], c32445[u], c436[u], c5377[u], c64[u], c75[u]);
}
int main() {
repeat(i32()) {
int n = i32();
repeat(n - 1) {
int u = i32();
int v = i32();
ch[u].push_back(v);
ch[v].push_back(u);
}
solve(1, 0);
printf("%d\n", ans);
ans = 0;
repeat(n) ch[it].clear();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 564ms
memory: 80964kb
input:
15 9 1 2 2 3 3 4 2 5 5 6 2 7 7 8 7 9 9999 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1...
output:
1 311255965 672169659 323323769 834196165 147532751 608867683 433545054 268282647 580524749 250163191 0 876200211 781358751 903681473
result:
ok 15 lines