QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#679835#5139. DFS Order 2jieloscWA 934ms339116kbC++202.8kb2024-10-26 18:50:222024-10-26 18:50:22

Judging History

你现在查看的是最新测评结果

  • [2024-10-26 18:50:22]
  • 评测
  • 测评结果:WA
  • 用时:934ms
  • 内存:339116kb
  • [2024-10-26 18:50:22]
  • 提交

answer

#include <bits/stdc++.h>
#define int int64_t

using std::cin;
using std::cout;
const char endl = '\n';

const int p = 998244353;
int fac[503] = {1};

std::vector<int> edge[502];
std::vector<int> son[502];
int sz[502];
int fa[502];
int subt[502];
void dfs(int u) {
  sz[u] = subt[u] = 1;
  for (auto &v : edge[u]) {
    if (v == fa[u]) continue;
    fa[v] = u;
    son[u].push_back(v);
    dfs(v);
    sz[u] += sz[v];
  }
  for (auto &v : son[u]) subt[u] = subt[u] * subt[v] % p;
  subt[u] = subt[u] * fac[son[u].size()] % p;
}

int Ans[502][502];

int n;

int bp[1000][1000];
int ans[1000][1000];

void ddfs(int u) {
  std::vector<std::vector<int>> bp(502, std::vector<int>(502, 0));
  // memset(bp, 0, sizeof(bp));
  // for (int i = 0; i < 502; ++i)
  //   for (int j = 0; j < 502; ++j) bp[i][j] = 0;
  bp[0][0] = 1;
  for (auto &v : son[u]) {
    for (int j = 500; j >= sz[v]; --j) {
      for (int k = 500; k; --k)
        bp[j][k] = (bp[j][k] + bp[j - sz[v]][k - 1] % p) % p;
    }
  }
  // for (int i = 0; i <= 500; i++) {
  //   for (int j = 0; j <= 500; j++)
  //     if (bp[i][j]) std::cerr << bp[i][j] << " \n"[j == 500];
  // }
  for (auto &v : son[u]) {
    for (int i = 0; i < 502; ++i)
      for (int j = 0; j < 502; ++j) ans[i][j] = bp[i][j];
    // auto ans = bp;
    for (int j = 0; j <= sz[u]; ++j) {
      for (int k = 0; k <= (int)son[u].size(); ++k) {
        if (j >= sz[v] and k >= 1)
          ans[j][k] = (ans[j][k] - ans[j - sz[v]][k - 1] % p) % p;
      }
    }
    int base = 1;
    for (auto vv : son[u])
      if (vv != v) base = base * subt[vv] % p;
    std::vector<int> anssj(502);
    for (int j = 0; j + sz[v] <= sz[u]; ++j) {
      for (int k = 0; k < (int)son[u].size(); ++k) {
        anssj[j] =
          (anssj[j] + ans[j][k] * fac[k] % p * fac[son[u].size() - k - 1] % p) %
          p;
      }
      anssj[j] = anssj[j] * base % p;
    }
    for (int j = 0; j < n; ++j) {
      for (int l = 0; l <= j; ++l) {
        Ans[v][j + 1] = (Ans[v][j + 1] + Ans[u][l] * anssj[j - l] % p) % p;
      }
    }
    ddfs(v);
  }
}

void solve() {
  for (int i = 1; i <= 500; ++i) fac[i] = fac[i - 1] * i % p;
  cin >> n;
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  dfs(1);
  Ans[1][1] = 1;
  ddfs(1);
  for (int u = 1; u <= n; ++u) {
    for (int j = 1; j <= n; ++j)
      cout << Ans[u][j] * subt[u] % p << " \n"[j == n];
  }
}

int32_t main() {
#ifndef _DEBUG
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
#endif
  int tc = 1;
  // std::cin >> tc;
  while (tc--) solve();
#ifdef _DEBUG
  std::cout << std::endl;
  std::cout << "Time used: " << clock() << "ms" << std::endl;
  system("pause");
  return 0;
#endif
}

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 16532kb

input:

5
1 2
1 3
3 4
3 5

output:

4 0 0 0 0
0 2 0 0 2
0 2 2 0 0
0 0 1 2 1
0 0 1 2 1

result:

ok 25 numbers

Test #2:

score: 0
Accepted
time: 11ms
memory: 19676kb

input:

10
9 2
9 6
10 5
1 5
1 6
9 3
5 8
4 3
7 9

output:

24 0 0 0 0 0 0 0 0 0
0 0 0 4 2 2 8 2 2 4
0 0 0 4 4 4 4 4 4 0
0 0 0 0 4 4 4 4 4 4
0 12 0 0 0 0 0 12 0 0
0 12 0 0 12 0 0 0 0 0
0 0 0 4 2 2 8 2 2 4
0 0 6 6 0 0 0 0 6 6
0 0 12 0 0 12 0 0 0 0
0 0 6 6 0 0 0 0 6 6

result:

ok 100 numbers

Test #3:

score: 0
Accepted
time: 96ms
memory: 79536kb

input:

100
18 100
91 87
28 83
11 98
51 52
24 91
72 53
18 19
89 16
77 35
26 25
73 16
96 70
56 44
69 10
63 30
54 95
39 66
58 98
8 71
58 65
74 73
2 64
12 19
32 81
31 54
43 41
84 59
55 75
72 81
59 37
10 94
93 2
64 47
13 32
36 84
28 22
30 28
25 77
47 6
80 52
54 17
23 40
47 88
49 53
65 27
99 59
25 70
91 9
74 1
7...

output:

8388559 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 62914557 0 62914557 62914557 0 62914557 0 0 0 62914557 0 62914557 ...

result:

ok 10000 numbers

Test #4:

score: 0
Accepted
time: 665ms
memory: 339116kb

input:

500
382 156
418 376
91 15
142 274
449 174
375 82
118 175
421 458
361 222
14 474
11 324
368 341
227 424
231 249
81 435
250 271
118 38
147 61
124 408
135 1
244 316
301 80
39 313
90 118
290 465
465 250
277 341
8 105
319 373
305 379
309 200
180 398
47 489
463 259
173 492
494 343
251 193
111 32
401 270
4...

output:

219078761 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 250000 numbers

Test #5:

score: 0
Accepted
time: 772ms
memory: 59624kb

input:

500
164 415
76 333
437 167
184 28
281 491
40 64
184 6
407 459
141 469
370 186
226 142
165 243
26 175
442 345
496 451
351 277
467 136
42 10
14 435
109 202
22 267
354 312
232 273
141 158
219 356
329 405
212 65
345 166
378 79
114 224
213 79
371 23
454 276
150 9
82 291
24 111
157 396
22 475
268 163
57 8...

output:

744716203 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 250000 numbers

Test #6:

score: 0
Accepted
time: 712ms
memory: 33720kb

input:

500
177 65
367 41
19 51
1 131
95 135
410 397
30 109
357 209
172 357
195 199
167 297
437 232
63 12
194 387
309 12
235 112
32 359
143 66
267 397
467 224
199 383
226 310
435 3
300 206
151 189
198 398
226 287
322 467
244 280
273 9
44 305
273 32
398 15
14 117
199 290
313 76
85 80
34 348
146 458
261 233
2...

output:

171992689 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 250000 numbers

Test #7:

score: -100
Wrong Answer
time: 934ms
memory: 28692kb

input:

500
381 446
399 209
190 247
83 319
1 278
101 82
1 224
1 75
391 382
303 231
220 92
446 494
112 342
73 218
1 148
210 334
1 57
212 44
450 495
17 473
173 122
424 1
196 465
47 305
321 143
458 88
10 439
1 243
391 144
300 397
332 1
232 1
1 152
366 1
100 483
111 25
416 63
242 280
110 1
119 1
234 365
1 475
5...

output:

566360865 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 752nd numbers differ - expected: '847598900', found: '-150645453'