QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290611 | #5213. 仙人掌 | MoRanSky | 100 ✓ | 91ms | 39044kb | C++23 | 1.7kb | 2023-12-25 06:05:27 | 2023-12-25 06:05:27 |
Judging History
answer
// Skyqwq
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
template <typename T> void inline read(T &x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
const int N = 5e5 + 5, P = 998244353;
int n, m, fa[N], d[N], c[N], deg[N], h[N];
vector<int> g[N];
bool vis[N];
void inline clr() {
for (int i = 1; i <= n; i++) vis[i] = 0, g[i].clear(), deg[i] = c[i] = 0;
}
void dfs(int u) {
vis[u] = 1;
for (int v: g[u]) {
if (!vis[v]) {
fa[v] = u;
d[v] = d[u] + 1;
dfs(v);
c[u] += c[v];
} else if (d[v] < d[u] && fa[u] != v) c[u]++, c[v]--;
}
}
void inline prework(int n) {
h[0] = 1;
h[1] = 1;
for (int i = 2; i <= n; i++) {
h[i] = (h[i - 1] + 1ll * (i - 1) * h[i - 2]) % P;
}
}
void inline work() {
for (int i = 2; i <= n; i++) {
if (c[i] > 1) {
puts("0");
return;
}
}
for (int i = 2; i <= n; i++) {
if (c[i] == 0) deg[fa[i]]++, deg[i]++;
}
int ans = 1;
for (int i = 1; i <= n; i++)
ans = 1ll * ans * h[deg[i]] % P;
printf("%d\n", ans);
}
int main() {
prework(N - 1);
int T; read(T);
while (T--) {
read(n), read(m);
for (int i = 1, u, v; i <= m; i++) {
read(u), read(v);
g[u].pb(v), g[v].pb(u);
}
dfs(1);
work();
clr();
}
return 0;
}
详细
Test #1:
score: 10
Accepted
time: 6ms
memory: 20156kb
input:
1 5 4 4 5 5 2 1 3 1 4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 10
Accepted
time: 3ms
memory: 19212kb
input:
92 10 10 8 4 8 7 8 5 8 6 1 9 6 10 5 2 4 1 6 3 8 2 10 11 4 6 2 3 7 10 9 7 4 2 2 5 2 1 1 5 7 3 2 9 2 8 10 12 7 1 7 2 7 9 9 4 7 4 4 3 5 10 3 8 5 3 10 7 1 5 8 6 10 10 9 6 9 1 10 4 4 5 8 2 1 3 9 7 9 8 7 5 8 10 10 11 7 1 5 9 3 6 9 4 10 5 3 8 3 10 7 4 6 4 10 7 3 2 10 12 5 1 6 7 10 4 9 2 2 7 4 6 3 1 5 9 4 3...
output:
64 4 0 4 0 0 16 1 0 1 0 0 32 2 0 8 0 0 16 0 0 40 4 0 40 0 0 32 0 0 16 0 0 80 0 0 1 4 0 8 2 0 8 0 0 16 4 0 8 0 0 16 0 0 16 0 0 2 0 0 4 0 0 2 8 1 32 0 0 16 2 0 32 0 0 4 4 0 4 0 0 4 0 0 2 0 0 16 8 0 0 336262384
result:
ok 92 numbers
Test #3:
score: 10
Accepted
time: 5ms
memory: 20984kb
input:
92 10 10 9 1 4 7 6 3 5 8 2 5 4 6 4 1 10 4 5 9 9 10 10 11 4 3 7 8 7 4 5 9 4 5 5 7 4 10 1 6 4 2 9 6 8 1 10 12 7 3 6 9 5 6 2 4 9 2 1 7 5 10 10 1 2 8 2 5 9 10 5 9 10 10 1 5 1 7 6 4 6 10 6 2 6 3 5 9 3 9 10 1 3 8 10 11 6 4 7 6 5 9 10 3 2 6 10 1 5 2 1 8 2 7 9 8 5 10 10 12 10 3 4 1 2 5 1 8 4 6 10 4 10 2 2 3...
output:
16 0 0 2 1 0 8 0 0 2 2 0 16 1 0 4 0 0 10 0 0 4 0 0 4 0 0 80 0 0 4 8 0 4 0 0 16 0 0 16 0 0 32 0 0 32 2 0 16 0 0 64 0 0 1 1 0 32 0 0 16 1 0 2 0 0 40 2 0 40 0 0 16 0 0 4 0 0 8 0 0 4 0 0 4 0 0 40 0 0 0 400539789
result:
ok 92 numbers
Test #4:
score: 10
Accepted
time: 23ms
memory: 29532kb
input:
140 7 6 4 5 1 6 3 2 6 7 2 1 5 3 9 8 9 6 3 4 6 8 4 1 8 7 7 3 1 5 2 9 13 12 1 13 9 7 4 11 5 3 8 2 6 1 11 5 7 8 3 10 12 6 10 12 2 4 16 15 6 11 1 13 3 4 15 6 11 5 16 14 12 7 10 12 4 16 2 8 5 3 9 10 13 15 8 9 7 1 18 17 6 9 2 1 1 13 5 12 12 17 8 11 11 4 14 8 4 5 16 7 15 10 9 15 3 2 17 6 7 14 13 18 18 16 1...
output:
32 128 2048 16384 65536 131072 262144 1048576 2097152 4194304 33554432 134217728 536870912 150994942 603979768 209715183 419430366 838860732 679477111 360709869 444595123 889190246 32990492 65980984 131961968 114902782 682155965 366067577 466025955 932051910 733474581 876574883 24888593 594625599 19...
result:
ok 140 numbers
Test #5:
score: 10
Accepted
time: 25ms
memory: 28424kb
input:
154 2 1 1 2 4 3 3 4 2 1 4 2 6 5 5 4 4 2 1 5 2 6 3 1 8 7 3 8 4 2 7 4 2 5 1 6 8 1 6 7 9 8 5 9 4 6 6 3 1 5 9 7 3 2 7 4 8 1 12 11 2 4 7 11 5 8 10 9 11 2 3 12 6 5 9 6 4 1 8 3 12 7 14 13 13 3 7 6 8 10 1 5 4 14 10 11 2 12 9 4 6 13 5 7 12 1 3 9 11 2 15 14 12 14 5 9 9 15 8 3 1 12 15 1 7 5 3 6 13 11 10 8 2 4 ...
output:
1 4 16 64 128 1024 4096 8192 16384 32768 65536 131072 262144 524288 1048576 4194304 16777216 67108864 150994942 209715183 419430366 838860732 679477111 360709869 125811497 251622994 503245988 57451391 682155965 732135154 865859467 733474581 468704809 937409618 876574883 511566473 49777186 199108744 ...
result:
ok 154 numbers
Test #6:
score: 10
Accepted
time: 15ms
memory: 24236kb
input:
102 20 19 8 3 18 19 16 5 10 2 8 13 14 9 14 6 8 14 6 18 3 17 11 20 8 11 3 10 18 15 8 1 10 12 8 16 17 7 16 4 20 19 8 5 7 20 5 13 2 18 18 19 3 15 11 4 18 3 5 17 2 9 16 11 4 6 15 1 4 7 11 2 2 8 19 12 18 10 6 14 20 19 13 17 18 8 3 5 7 20 18 1 1 15 13 16 13 19 16 6 18 7 5 10 13 18 13 3 13 9 8 12 8 11 12 2...
output:
622592 409600 972800 532480 512000 409600 1187840 665600 327680 692224 832000 512000 327680 512000 778240 532480 1011712 327680 425984 950272 262144 778240 1564672 665600 665600 327680 327680 692224 1848320 665600 972800 622592 409600 512000 1955840 409600 512000 665600 665600 409600 425984 327680 1...
result:
ok 102 numbers
Test #7:
score: 10
Accepted
time: 18ms
memory: 24752kb
input:
102 20 19 9 12 3 19 11 2 8 3 6 7 19 13 11 14 8 6 20 1 12 20 11 16 8 10 6 15 20 17 7 18 16 4 7 9 8 5 8 11 20 19 14 19 11 4 11 9 1 7 20 2 15 11 18 17 11 16 15 14 16 18 14 5 20 1 4 8 10 3 9 13 20 12 20 6 11 10 20 15 20 19 18 2 5 11 18 4 15 19 17 16 17 15 12 7 1 6 17 12 15 13 5 20 12 5 3 18 16 1 17 3 16...
output:
532480 692224 409600 665600 532480 327680 409600 622592 409600 409600 1264640 532480 832000 532480 409600 972800 692224 778240 778240 409600 512000 665600 972800 512000 512000 425984 665600 512000 409600 622592 512000 409600 950272 532480 1124864 1187840 665600 532480 972800 425984 327680 692224 622...
result:
ok 102 numbers
Test #8:
score: 10
Accepted
time: 91ms
memory: 38496kb
input:
2503 20 19 2 14 1 20 13 5 2 16 11 10 16 17 2 18 13 2 2 3 5 4 11 19 10 12 6 15 13 6 19 7 19 9 13 11 14 8 5 1 20 20 14 10 16 15 19 20 20 4 5 13 4 1 9 3 18 9 19 12 4 6 17 8 18 11 2 5 14 18 16 19 3 13 16 17 20 14 17 2 12 7 20 21 2 10 17 15 1 19 1 16 7 20 1 8 10 15 5 12 7 6 7 4 9 13 1 9 13 18 9 7 16 14 7...
output:
532480 8 0 0 0 327680 20480 0 0 0 665600 128 512 0 0 512000 32000 0 0 0 409600 33280 8 0 0 512000 40960 0 0 0 532480 512 0 0 0 532480 10240 32 0 0 409600 10240 0 0 0 512000 40960 0 0 0 409600 13312 0 0 0 327680 512 640 0 0 425984 51200 0 0 0 409600 26624 0 0 0 532480 1280 640 0 0 1264640 1280 0 0 0 ...
result:
ok 2503 numbers
Test #9:
score: 10
Accepted
time: 82ms
memory: 38624kb
input:
2503 20 19 11 5 19 18 9 12 2 1 17 8 17 16 17 11 14 10 7 20 17 7 2 9 3 4 13 6 11 15 19 13 2 19 1 3 13 14 2 17 20 20 4 9 10 17 13 6 15 14 4 2 10 20 12 18 18 19 1 16 6 11 13 5 10 1 12 7 7 3 2 14 20 13 10 4 17 12 17 15 2 8 20 21 15 20 8 2 4 19 11 1 19 5 18 4 7 9 5 18 8 16 7 17 8 15 13 14 13 4 18 10 7 12...
output:
532480 1024 0 0 0 532480 4160 0 0 0 425984 10240 640 0 0 327680 1280 0 0 0 532480 16640 0 0 0 409600 512 0 0 0 425984 81920 0 0 0 327680 2560 256 0 0 1264640 2048 0 0 0 512000 800 0 0 0 778240 5120 0 0 0 1011712 12800 0 0 0 778240 1024 0 0 0 532480 40960 0 0 0 972800 512 0 0 0 409600 1024 0 0 0 5324...
result:
ok 2503 numbers
Test #10:
score: 10
Accepted
time: 85ms
memory: 39044kb
input:
2503 20 19 14 11 5 8 2 17 17 1 12 10 3 15 8 19 5 4 15 2 15 7 14 6 16 13 8 12 20 14 18 3 18 20 18 9 8 16 3 5 20 20 3 7 4 20 1 17 11 3 1 6 12 5 11 10 10 8 14 1 10 9 1 11 16 15 18 12 1 16 12 13 18 19 12 2 19 4 14 18 12 15 20 21 4 15 7 12 15 5 18 4 5 8 15 17 10 6 3 9 19 16 19 10 13 19 9 14 7 1 18 3 18 1...
output:
327680 2048 0 0 0 409600 4096 0 0 0 532480 416 0 0 0 409600 3328 256 0 0 1011712 64000 0 0 0 532480 2560 0 0 0 327680 10240 128 0 0 665600 5120 0 0 0 692224 2048 0 0 0 425984 320 0 0 0 532480 20480 0 0 0 532480 16384 0 0 0 532480 2560 0 0 0 532480 32000 0 0 0 262144 5120 512 0 0 409600 3328 0 0 0 53...
result:
ok 2503 numbers
Extra Test:
score: 0
Extra Test Passed