結果

問題 No.1507 Road Blocked
ユーザー trineutrontrineutron
提出日時 2021-05-14 22:21:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 869 bytes
コンパイル時間 2,350 ms
コンパイル使用メモリ 201,768 KB
実行使用メモリ 18,560 KB
最終ジャッジ日時 2024-04-10 00:49:44
合計ジャッジ時間 6,886 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 93 ms
18,560 KB
testcase_04 AC 116 ms
9,088 KB
testcase_05 AC 113 ms
9,188 KB
testcase_06 AC 112 ms
9,216 KB
testcase_07 AC 106 ms
9,176 KB
testcase_08 AC 109 ms
9,088 KB
testcase_09 AC 112 ms
9,096 KB
testcase_10 AC 109 ms
9,216 KB
testcase_11 AC 109 ms
9,216 KB
testcase_12 AC 114 ms
9,088 KB
testcase_13 AC 108 ms
9,216 KB
testcase_14 AC 110 ms
9,216 KB
testcase_15 AC 116 ms
9,088 KB
testcase_16 AC 109 ms
9,260 KB
testcase_17 AC 113 ms
9,216 KB
testcase_18 AC 107 ms
9,088 KB
testcase_19 AC 114 ms
9,088 KB
testcase_20 AC 111 ms
9,088 KB
testcase_21 AC 118 ms
9,216 KB
testcase_22 AC 111 ms
9,088 KB
testcase_23 AC 111 ms
9,088 KB
testcase_24 AC 116 ms
9,216 KB
testcase_25 AC 113 ms
9,088 KB
testcase_26 AC 113 ms
9,088 KB
testcase_27 AC 110 ms
9,164 KB
testcase_28 AC 114 ms
9,216 KB
testcase_29 AC 115 ms
9,088 KB
testcase_30 AC 113 ms
9,088 KB
testcase_31 AC 114 ms
9,216 KB
testcase_32 AC 111 ms
9,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>

using namespace std;
using namespace atcoder;

using mint = modint998244353;
using graph = vector<vector<int>>;

int n;

mint dfs(const graph &to, vector<int> &sz, int v, int p)
{
    mint res = 0;
    for (auto &&c : to.at(v))
    {
        if (c == p)
        {
            continue;
        }
        res += dfs(to, sz, c, v);
        sz.at(v) += sz.at(c);
        res += mint(n) * (n - 1) / 2 - mint(sz.at(c)) * (n - sz.at(c));
    }
    sz.at(v)++;
    return res;
}

int main()
{
    cin >> n;
    graph to(n);
    for (int i = 0; i < n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        to.at(u).push_back(v);
        to.at(v).push_back(u);
    }
    vector<int> sz(n);
    cout << (dfs(to, sz, 0, -1) / (mint(n) * (n - 1) * (n - 1) / 2)).val() << endl;
    return 0;
}
0