QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#858814 | #9910. 颠倒歌 | Xiaohuba | 45 | 2530ms | 281344kb | C++23 | 5.4kb | 2025-01-17 00:08:19 | 2025-01-17 00:08:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// #define LOCK_GETCHAR
// #define USE_INT_128
#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define CONSTEXPR_FUNC
#define ENABLE_IF_INT
#else
#define CONSTEXPR_FUNC constexpr
#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif
#endif
#if !defined(_WIN32) && !defined(__CYGWIN__) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif
#define il inline
#define mkp make_pair
#define fi first
#define se second
#define ssz(x) (signed((x).size()))
#define _loop_i_t(j, k) make_signed_t<decltype((j) - (k))>
#define For(i, j, k) for (_loop_i_t(j, k) i = (j); i <= (k); ++i) // NOLINT
#define ForDown(i, j, k) \
for (_loop_i_t(j, k) i = (j); i >= decltype(i)(k); --i) // NOLINT
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename) \
freopen(filename ".in", "r", stdin); \
freopen(filename ".out", "w", stdout)
#else
#define FileIO(filename) void(0)
#endif
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif
// clang-format off
CONSTEXPR_FUNC il ll qpow(ll x, ull y, ll mod){ ll ans = 1; x %= mod; while (y) { if (y & 1) (ans *= x) %= mod; (x *= x) %= mod; y >>= 1; } return ans; }
template<typename T> CONSTEXPR_FUNC il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> CONSTEXPR_FUNC il void cmax(T & x, const T &y){ x = max(x, y); }
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + (c - '0'); c = getchar(); } x *= f; }
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x), read(y...); }
// clang-format on
// File head end
namespace {
constexpr ll MAXN = 5005, MAXK = 1005, mod = 998244353;
int p, k, n;
vector<int> T[MAXK][MAXN];
namespace Sol1 {
void solve() {}
} // namespace Sol1
namespace Sol2 {
vector<int> cur[MAXN * 2], ins[MAXN * 2], nxt[MAXN * 2];
int cur_sz, ins_sz;
int trans(vector<int> *tr, vector<int> *dist) {
For(i, 1, 2 * n) dist[i].clear();
int cnt = 0;
auto dfs = [&](auto &&self, int x, int pre) -> void {
cnt++;
int tmp;
if (pre)
dist[n + cnt].eb(pre), dist[pre].eb(n + cnt);
while (!pre || ssz(tr[x]) == 2)
dist[n + cnt].eb(x), dist[x].eb(n + cnt),
tmp = x, x = tr[x][tr[x][0] == pre], pre = tmp;
dist[n + cnt].eb(x), dist[x].eb(n + cnt);
for (int v : tr[x])
if (v != pre)
self(self, v, x);
};
int p = 1;
while (ssz(tr[p]) != 1)
p++;
dfs(dfs, p, 0);
return n + cnt;
}
/* unordered_ */ map<pii, vector<int>> mp;
/* unordered_ */ set<pii> have;
int bl[MAXN], fa[MAXN * 2];
void merge() {
mp.clear(), have.clear();
fill(bl, bl + 1 + n, -1);
auto dfs1 = [&](auto &&self, int x, int pre) -> void {
// cerr << x << '\n';
fa[x] = pre;
if (x > n)
for (int v : cur[x])
if (v != pre)
bl[v] = x - n;
for (int v : cur[x])
if (v != pre)
self(self, v, x);
};
assert(cur_sz > n);
dfs1(dfs1, n + 1, 0);
For(i, n + 1, ins_sz) for (int u : ins[i]) {
if (~bl[u])
mp[{bl[u], i - n}].eb(u);
have.emplace(i - n, u);
}
int cnt2 = 0;
For(i, 1, 2 * n) nxt[i].clear();
for (const auto &[key, vec] : mp) {
if (ssz(vec) > 1) {
cnt2++;
for (int u : vec)
nxt[u].eb(n + cnt2), nxt[n + cnt2].eb(u);
if (have.count({key.se, fa[key.fi + n]}))
nxt[fa[key.fi + n]].eb(n + cnt2), nxt[n + cnt2].eb(fa[key.fi + n]);
} else if (have.count({key.se, fa[key.fi + n]})) {
cnt2++;
nxt[vec[0]].eb(n + cnt2), nxt[n + cnt2].eb(vec[0]);
nxt[fa[key.fi + n]].eb(n + cnt2), nxt[n + cnt2].eb(fa[key.fi + n]);
}
}
cur_sz = cnt2 + n;
For(i, 1, 2 * n) cur[i].swap(nxt[i]);
}
void solve() {
cur_sz = trans(T[1], cur);
// cerr << cur_sz << '\n';
// For(i, n + 1, cur_sz) for (int j : cur[i]) cerr << i << ' ' << j << '\n';
For(i, 2, k) {
// cerr << "> " << i << '\n';
ins_sz = trans(T[i], ins);
// if (i == 3) {
// For(j, n + 1, ins_sz) for (int k : ins[j]) cerr << k << ' ' << j <<
// '\n'; cerr << "---\n"; For(j, n + 1, ins_sz) for (int k : cur[j]) cerr
// << k << ' ' << j << '\n'; cerr << "---\n";
// }
merge();
}
ll ans = 1;
For(i, n + 1, cur_sz) if (ssz(cur[i]) > 1) {
(ans *= qpow(ssz(cur[i]), ssz(cur[i]) - 2, mod)) %= mod;
}
cout << ans << '\n';
}
} // namespace Sol2
void Main() {
read(p, k, n);
For(i, 1, k) For(j, 1, n - 1) {
int u, v;
read(u, v), T[i][u].eb(v), T[i][v].eb(u);
}
(p == 0) ? Sol1::solve() : Sol2::solve();
}
} // namespace
signed main() { return Main(), 0; }
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 5ms
memory: 3584kb
input:
1 4 7 1 7 4 1 2 3 2 6 5 4 7 2 5 7 7 3 1 2 4 1 4 3 5 6 5 4 2 4 3 5 7 2 2 6 1 7 1 7 6 4 5 2 3 6 3 1 4 5
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Wrong Answer
time: 4ms
memory: 3584kb
input:
0 3 6 6 4 1 3 4 1 5 2 4 5 6 4 3 1 2 5 3 4 5 4 4 1 3 1 5 2 5 4 6 4
output:
result:
wrong answer 1st lines differ - expected: '2', found: ''
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 4ms
memory: 3584kb
input:
0 1 189 77 175 145 175 4 175 92 175 175 33 175 125 175 185 157 175 186 175 115 175 113 175 38 175 175 138 175 133 175 48 175 128 175 66 175 34 175 148 150 175 175 104 175 84 175 59 175 154 80 175 176 175 135 175 55 175 139 175 175 132 175 91 13 175 175 110 155 175 175 60 175 184 73 175 152 175 83 17...
output:
result:
wrong answer 1st lines differ - expected: '5245226', found: ''
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 7
Accepted
Test #25:
score: 7
Accepted
time: 6ms
memory: 3584kb
input:
1 1 156 69 74 65 126 110 16 134 129 3 22 78 5 140 23 53 138 109 67 82 74 42 57 23 143 12 112 7 13 154 105 100 118 63 28 41 37 145 25 80 142 111 148 81 85 133 13 104 89 83 14 39 24 120 97 98 131 94 55 107 91 38 130 122 36 2 32 82 94 35 49 40 108 68 146 101 130 101 76 105 58 80 137 152 87 78 66 32 55 ...
output:
261947439
result:
ok single line: '261947439'
Test #26:
score: 7
Accepted
time: 5ms
memory: 3584kb
input:
1 1 168 140 135 69 51 33 66 138 48 168 90 102 43 137 98 117 21 88 131 29 14 117 157 77 78 85 88 119 32 114 68 55 67 160 166 12 149 155 85 20 113 132 149 131 19 97 139 22 78 16 157 151 143 99 156 159 71 72 119 161 163 68 28 101 89 27 133 96 146 125 44 151 24 14 114 116 111 89 25 115 138 46 1 51 47 40...
output:
260505142
result:
ok single line: '260505142'
Test #27:
score: 7
Accepted
time: 4ms
memory: 3456kb
input:
1 1 155 77 28 89 81 138 11 85 7 124 53 29 52 116 32 151 66 103 80 145 77 82 51 116 138 141 144 57 20 34 101 14 84 75 68 42 64 95 117 117 137 122 33 76 50 12 71 112 44 134 83 134 18 105 10 75 122 106 94 84 69 1 123 140 10 70 71 78 133 24 152 87 13 9 31 135 142 101 146 149 129 28 16 52 39 26 119 146 3...
output:
252700555
result:
ok single line: '252700555'
Test #28:
score: 7
Accepted
time: 5ms
memory: 3584kb
input:
1 1 200 24 110 97 182 163 183 115 67 21 193 168 118 88 19 10 150 33 76 15 184 138 131 166 143 151 167 17 60 188 92 110 33 9 65 186 74 198 170 144 161 69 134 179 189 191 70 64 79 10 84 65 107 66 149 123 191 184 141 107 30 170 129 159 186 108 132 17 68 46 198 158 41 13 55 101 59 20 72 200 63 128 23 89...
output:
85910356
result:
ok single line: '85910356'
Subtask #8:
score: 7
Accepted
Dependency #7:
100%
Accepted
Test #29:
score: 7
Accepted
time: 4ms
memory: 3584kb
input:
1 1 170 104 123 43 65 8 61 169 138 20 160 34 169 133 25 129 2 115 137 64 168 33 35 77 38 128 166 159 151 78 3 155 34 6 140 16 133 26 117 13 143 144 150 7 131 64 61 162 52 149 16 17 80 136 77 141 83 54 146 85 47 140 24 107 158 91 152 66 43 24 21 86 38 141 85 51 11 162 151 2 66 73 74 9 26 156 68 121 1...
output:
83894725
result:
ok single line: '83894725'
Test #30:
score: 7
Accepted
time: 5ms
memory: 3584kb
input:
1 1 168 46 92 25 154 91 121 21 31 100 152 24 35 115 67 139 111 113 90 88 69 134 83 127 120 74 23 22 108 28 18 58 36 15 125 100 167 3 127 112 34 7 25 3 23 40 13 29 138 124 118 33 143 8 32 17 58 20 120 12 148 158 130 115 122 26 29 90 157 111 73 57 64 79 80 153 159 89 73 50 79 62 105 109 135 96 32 27 1...
output:
314954106
result:
ok single line: '314954106'
Test #31:
score: 7
Accepted
time: 4ms
memory: 3584kb
input:
1 1 173 71 145 155 153 150 80 164 52 158 173 116 96 169 100 59 20 143 151 43 73 66 38 77 161 39 91 166 11 35 136 4 145 65 37 163 67 138 140 170 31 28 124 85 104 27 2 50 129 76 82 69 155 36 33 86 112 58 23 89 40 47 3 64 27 94 110 36 22 47 67 99 19 165 134 55 131 16 118 68 144 45 53 52 35 125 6 120 77...
output:
223769237
result:
ok single line: '223769237'
Test #32:
score: 7
Accepted
time: 3ms
memory: 3456kb
input:
1 1 200 14 29 23 169 138 142 67 145 166 102 126 183 108 69 170 70 85 194 79 132 174 154 30 130 133 21 93 86 68 183 83 168 160 114 4 94 33 11 109 16 98 18 115 27 52 146 88 103 54 7 49 158 121 110 159 55 190 177 193 85 63 8 155 140 43 117 149 93 169 48 125 133 180 95 189 199 78 162 24 144 84 5 135 39 ...
output:
792535599
result:
ok single line: '792535599'
Subtask #9:
score: 10
Accepted
Dependency #8:
100%
Accepted
Test #33:
score: 10
Accepted
time: 3ms
memory: 3712kb
input:
1 2 160 85 103 57 106 55 79 43 92 96 116 100 68 93 88 103 24 70 144 7 12 142 123 95 77 134 15 16 153 98 74 8 150 56 142 47 58 91 54 65 59 77 131 101 47 17 8 10 5 61 97 89 115 46 96 92 36 43 34 159 139 73 28 66 151 44 76 18 13 33 76 127 67 4 33 9 102 126 9 133 141 88 109 32 27 50 117 128 140 126 10 7...
output:
138251585
result:
ok single line: '138251585'
Test #34:
score: 10
Accepted
time: 3ms
memory: 3712kb
input:
1 2 170 18 31 34 76 122 66 130 150 32 115 155 69 153 46 77 92 26 83 15 109 93 116 142 62 133 25 99 114 117 37 64 102 152 122 143 86 157 110 10 16 98 51 96 139 52 45 55 108 78 166 137 142 160 80 45 40 7 94 132 54 9 81 153 141 54 70 4 60 127 91 13 26 120 152 124 161 94 82 106 61 121 30 111 77 160 165 ...
output:
402212722
result:
ok single line: '402212722'
Test #35:
score: 10
Accepted
time: 5ms
memory: 3712kb
input:
1 2 165 164 110 44 89 147 71 66 57 104 142 60 31 125 62 163 158 141 161 15 157 109 54 114 108 143 45 25 10 83 75 88 36 118 122 97 72 79 19 19 72 148 153 79 132 153 3 23 130 7 91 148 17 10 46 78 65 151 85 16 128 137 82 136 162 126 75 72 1 101 117 50 60 43 132 69 63 27 94 110 155 162 33 107 140 124 20...
output:
239138702
result:
ok single line: '239138702'
Test #36:
score: 10
Accepted
time: 5ms
memory: 3584kb
input:
1 2 200 48 108 140 189 123 65 47 102 83 53 173 26 176 45 32 167 99 155 7 91 58 136 85 35 40 147 49 70 75 163 94 114 25 16 128 3 47 172 20 191 4 120 187 38 52 98 30 162 151 85 96 124 169 125 175 74 183 163 178 78 192 154 63 76 175 88 136 5 150 83 54 191 134 145 181 60 151 160 152 141 142 66 100 52 15...
output:
94911555
result:
ok single line: '94911555'
Subtask #10:
score: 10
Accepted
Dependency #9:
100%
Accepted
Test #37:
score: 10
Accepted
time: 6ms
memory: 4096kb
input:
1 31 151 94 56 7 113 142 50 51 81 131 1 25 10 74 106 87 68 43 76 25 91 128 116 12 61 75 34 43 5 36 53 13 41 48 51 40 73 89 69 59 34 62 10 133 107 89 49 139 53 91 97 125 23 35 44 22 135 98 105 4 83 49 26 100 48 2 110 28 52 3 96 46 96 15 6 132 78 109 73 145 81 69 102 54 92 30 56 74 117 11 146 70 26 99...
output:
494673301
result:
ok single line: '494673301'
Test #38:
score: 10
Accepted
time: 7ms
memory: 4096kb
input:
1 36 194 118 43 73 36 56 124 49 9 173 28 81 113 156 117 151 110 5 117 67 187 18 146 70 177 38 65 59 120 115 13 165 78 75 152 146 87 39 48 151 185 85 120 101 62 177 174 133 166 160 105 84 43 128 149 193 49 153 126 99 78 123 98 116 159 106 98 61 20 48 54 182 114 31 92 50 159 45 102 18 50 178 62 147 14...
output:
248295050
result:
ok single line: '248295050'
Test #39:
score: 10
Accepted
time: 7ms
memory: 4224kb
input:
1 36 164 110 58 147 116 133 17 26 1 160 143 11 112 123 113 97 37 138 132 73 80 67 56 138 142 40 33 115 153 52 6 126 81 124 76 122 83 135 114 67 129 109 89 62 76 36 98 57 91 63 64 85 41 155 118 86 13 12 63 77 15 117 54 146 112 118 26 70 72 74 55 128 98 50 28 30 139 29 78 108 66 105 7 21 78 151 104 11...
output:
273498099
result:
ok single line: '273498099'
Test #40:
score: 10
Accepted
time: 7ms
memory: 4224kb
input:
1 40 200 103 35 185 125 34 90 176 65 48 50 42 77 80 105 82 151 144 26 59 173 81 142 41 192 167 198 131 20 126 6 19 179 122 170 116 120 86 178 147 149 89 168 111 6 3 100 24 166 18 34 169 74 17 95 8 73 46 184 154 52 92 83 129 164 190 77 90 37 87 144 200 70 131 16 113 161 181 98 99 139 150 43 200 78 12...
output:
6219604
result:
ok single line: '6219604'
Subtask #11:
score: 11
Accepted
Dependency #10:
100%
Accepted
Test #41:
score: 11
Accepted
time: 1599ms
memory: 194432kb
input:
1 820 4113 2108 233 4008 3416 4006 2604 1450 3610 1459 246 3094 1565 3052 3604 3985 3162 1804 92 2848 785 259 2585 2085 1942 1910 68 1191 4039 955 4056 1005 4030 2495 3228 4089 2400 439 2097 2861 663 649 3609 3112 3272 3690 1220 2456 1644 2912 2530 408 2209 2105 2253 851 51 419 3407 2193 2784 280 26...
output:
728750489
result:
ok single line: '728750489'
Test #42:
score: 11
Accepted
time: 1610ms
memory: 199424kb
input:
1 919 3763 671 1387 863 3725 1050 3483 219 1528 2871 1049 1787 2307 366 783 1672 1645 420 811 1524 369 740 2151 2160 2692 1348 1150 2917 3299 879 1377 682 1861 3044 775 505 3740 3032 3005 3459 1074 298 698 3257 3694 548 2394 1365 2769 1250 3627 1752 485 1704 3455 793 2764 2111 806 3334 486 2178 2719...
output:
617892430
result:
ok single line: '617892430'
Test #43:
score: 11
Accepted
time: 1557ms
memory: 188928kb
input:
1 785 4171 2289 39 3598 563 1549 2149 668 3461 2945 2471 1956 2552 2892 3836 2573 1834 2927 1909 1371 7 874 2271 3975 2907 3223 1098 3083 3893 652 1379 2043 955 1038 4154 2536 1289 3275 3257 3215 198 221 4026 537 3465 3470 646 4128 827 980 3796 142 3490 208 2701 3262 4114 1862 2408 1073 2695 4049 27...
output:
286098367
result:
ok single line: '286098367'
Test #44:
score: 11
Accepted
time: 2530ms
memory: 281344kb
input:
1 1000 5000 233 1051 3865 2813 3677 4977 2643 1598 495 1347 4910 1009 2728 288 2631 2123 3621 1471 2014 2079 2423 4772 2156 592 1687 3441 1394 4842 946 3367 925 3249 1553 892 3670 2729 2112 861 2987 1987 581 1751 1691 103 934 1488 766 4655 3017 2370 3504 1834 1288 2662 1498 3550 238 1058 4776 1182 1...
output:
25113695
result:
ok single line: '25113695'