結果

問題 No.2584 The University of Tree
ユーザー fdironiafdironia
提出日時 2024-01-24 08:17:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 565 ms / 3,000 ms
コード長 2,132 bytes
コンパイル時間 1,082 ms
コンパイル使用メモリ 93,404 KB
実行使用メモリ 58,152 KB
最終ジャッジ日時 2024-09-28 07:01:12
合計ジャッジ時間 16,154 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 259 ms
30,848 KB
testcase_23 AC 282 ms
19,968 KB
testcase_24 AC 175 ms
12,800 KB
testcase_25 AC 208 ms
14,336 KB
testcase_26 AC 135 ms
12,288 KB
testcase_27 AC 266 ms
20,992 KB
testcase_28 AC 136 ms
15,104 KB
testcase_29 AC 73 ms
9,600 KB
testcase_30 AC 524 ms
35,548 KB
testcase_31 AC 538 ms
43,720 KB
testcase_32 AC 110 ms
15,616 KB
testcase_33 AC 449 ms
56,960 KB
testcase_34 AC 101 ms
9,600 KB
testcase_35 AC 550 ms
43,136 KB
testcase_36 AC 555 ms
30,464 KB
testcase_37 AC 551 ms
28,288 KB
testcase_38 AC 525 ms
27,776 KB
testcase_39 AC 539 ms
34,428 KB
testcase_40 AC 557 ms
44,160 KB
testcase_41 AC 557 ms
39,472 KB
testcase_42 AC 547 ms
43,520 KB
testcase_43 AC 542 ms
39,552 KB
testcase_44 AC 563 ms
49,408 KB
testcase_45 AC 565 ms
49,280 KB
testcase_46 AC 477 ms
58,152 KB
testcase_47 AC 509 ms
30,464 KB
testcase_48 AC 185 ms
12,800 KB
testcase_49 AC 485 ms
25,472 KB
testcase_50 AC 383 ms
21,888 KB
testcase_51 AC 201 ms
13,952 KB
testcase_52 AC 93 ms
8,448 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
      |         ~~~~~~~~~^~~~~~~

ソースコード

diff #

#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 * pu * (u + 1) % Z;
        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;
}
0