結果

問題 No.1418 Sum of Sum of Subtree Size
ユーザー 👑 hitonanodehitonanode
提出日時 2021-02-06 14:15:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 855 bytes
コンパイル時間 2,105 ms
コンパイル使用メモリ 76,820 KB
実行使用メモリ 12,240 KB
最終ジャッジ日時 2023-09-15 20:52:04
合計ジャッジ時間 4,063 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,732 KB
testcase_01 AC 3 ms
5,636 KB
testcase_02 AC 3 ms
5,764 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 54 ms
7,924 KB
testcase_09 AC 25 ms
6,672 KB
testcase_10 AC 28 ms
6,924 KB
testcase_11 AC 17 ms
6,212 KB
testcase_12 AC 42 ms
7,344 KB
testcase_13 AC 52 ms
7,680 KB
testcase_14 AC 52 ms
7,988 KB
testcase_15 AC 39 ms
7,240 KB
testcase_16 AC 7 ms
5,836 KB
testcase_17 AC 7 ms
5,936 KB
testcase_18 AC 73 ms
8,588 KB
testcase_19 AC 15 ms
6,216 KB
testcase_20 AC 5 ms
5,700 KB
testcase_21 AC 38 ms
7,164 KB
testcase_22 AC 32 ms
7,028 KB
testcase_23 AC 6 ms
5,720 KB
testcase_24 AC 6 ms
5,856 KB
testcase_25 AC 5 ms
5,840 KB
testcase_26 AC 5 ms
5,748 KB
testcase_27 AC 3 ms
5,648 KB
testcase_28 AC 4 ms
5,740 KB
testcase_29 AC 6 ms
5,824 KB
testcase_30 AC 6 ms
5,840 KB
testcase_31 AC 4 ms
5,768 KB
testcase_32 AC 5 ms
5,704 KB
testcase_33 AC 18 ms
7,232 KB
testcase_34 WA -
testcase_35 AC 33 ms
8,504 KB
testcase_36 AC 10 ms
6,376 KB
testcase_37 AC 55 ms
8,648 KB
testcase_38 AC 51 ms
8,464 KB
testcase_39 AC 3 ms
5,660 KB
testcase_40 AC 4 ms
5,776 KB
testcase_41 AC 3 ms
5,636 KB
testcase_42 AC 4 ms
5,656 KB
testcase_43 AC 3 ms
5,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 想定 WA
#include <vector>
#include <iostream>
using namespace std;

vector<int> to[100000];

int main() {

    int N;
    cin >> N;

    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    long long ret = 1LL * N * N;

    // オーバーフローで WA になるべき
    auto f = [&N](long long x) -> int { return x * (N - x); };

    auto dfs = [&](auto self, int now, int prv) -> int {
        int subtree_size = 1;
        for (auto nxt : to[now]) {
            if (nxt != prv) {
                int tmp = self(self, nxt, now);
                ret += f(tmp);
                subtree_size += tmp;
            }
        }
        ret += f(subtree_size);
        return subtree_size;
    };
    dfs(dfs, 0, -1);
    cout << ret << '\n';
}
0