結果
問題 | No.2584 The University of Tree |
ユーザー | fdironia |
提出日時 | 2024-01-24 08:16:59 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,128 bytes |
コンパイル時間 | 1,078 ms |
コンパイル使用メモリ | 93,768 KB |
実行使用メモリ | 58,160 KB |
最終ジャッジ日時 | 2024-09-28 07:00:50 |
合計ジャッジ時間 | 16,518 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | WA | - |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 118 ms
15,616 KB |
testcase_33 | WA | - |
testcase_34 | AC | 113 ms
9,728 KB |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | AC | 535 ms
30,584 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
コンパイルメッセージ
main.cpp: In function 'void dfs1(vp*, int, int, vi*, int*)': main.cpp:46:19: warning: '*pos[1]' may be used uninitialized [-Wmaybe-uninitialized] 46 | ans[u] = pos[1]; | ~~~~~^ In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:50, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39, from main.cpp:1: In function 'constexpr typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int*; _Tp = int]', inlined from 'constexpr void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = int*; _Tp = int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:968:21, inlined from 'constexpr void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int*; _Tp = int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:998:20, inlined from 'int main()' at main.cpp:66:9: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:922:18: warning: 'void* __builtin_memset(void*, int, long unsigned int)' specified bound between 18446744065119617024 and 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=] 922 | *__first = __tmp; | ~~~~~~~~~^~~~~~~
ソースコード
#include <iostream> #include <vector> #include <utility> using namespace std; constexpr int Z = 998244353; using pii = pair<int, int>; using vp = vector<pii>; using vi = vector<int>; void dfs0(vp e[], int u, int p, int pord, vi dp[]) { dp[u].resize(e[u].size()); dp[u][0] = 1; for (int i = 1; i < (int)e[u].size(); i++) { int v = e[u][i].second; if (v == p) { e[p][pord].first = i; e[u][i].first = pord; } else { dfs0(e, v, u, i, dp); int ord = e[u][i].first, dv = e[v].size(); for (int j = 0; j < (int)e[v].size() - 1; j++) { dp[u][i] = 1ll * (dp[u][i] + dp[v][(ord-1-j+dv)%dv]) * (v + 1) % Z; } } } } void dfs1(vp e[], int u, int p, vi dp[], int ans[]) { int pre[e[u].size()]; int pu = 1; for (int i = 0; i < (int)e[u].size(); i++) { pu = 1ll * (u + 1) * pu; pre[i] = ((i == 0 ? 0 : pre[i-1]) + 1ll * pu * dp[u][i]) % Z; } int pos[e[u].size()+1]; for (int i = (int)e[u].size(); i >= 0; i--) { pos[i] = i == (int)e[u].size() ? 0 : 1ll * (pos[i+1] + dp[u][i]) * (u + 1) % Z; } ans[u] = pos[1]; pu = 1; for (int i = (int)e[u].size() - 1; i >= 1; i--) { auto [ord, v] = e[u][i]; if (v != p) { dp[v][ord] = (pos[i+1] + 1ll * pu * pre[i-1]) % Z; dfs1(e, v, u, dp, ans); } pu = 1ll * pu * (u + 1) % Z; } } int main() { int n; cin >> n; vp e[n]; int e2[n-1]; fill(e2, e2 + n - 1, 0); for (int i = 0; i < n; i++) { int d; cin >> d; e[i].resize(d + 1); for (int j = 1; j <= d; j++) { cin >> e[i][j].first; e2[--e[i][j].first] ^= i; } } for (int i = 0; i < n; i++) { for (int j = 1; j < (int)e[i].size(); j++) { e[i][j].second = e2[e[i][j].first] ^ i; } } vi dp[n]; dfs0(e, 0, -1, -1, dp); int ans[n]; dfs1(e, 0, -1, dp, ans); for (int i = 0; i < n; i++) { cout << ans[i] << endl; } return 0; }