結果

問題 No.1507 Road Blocked
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-14 22:33:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 4,163 ms
コンパイル使用メモリ 261,204 KB
実行使用メモリ 13,100 KB
最終ジャッジ日時 2023-07-25 07:48:33
合計ジャッジ時間 8,771 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 70 ms
13,100 KB
testcase_04 AC 92 ms
8,592 KB
testcase_05 AC 91 ms
8,556 KB
testcase_06 AC 91 ms
8,588 KB
testcase_07 AC 95 ms
8,600 KB
testcase_08 AC 93 ms
8,556 KB
testcase_09 AC 96 ms
8,592 KB
testcase_10 AC 93 ms
8,640 KB
testcase_11 AC 90 ms
8,600 KB
testcase_12 AC 93 ms
8,904 KB
testcase_13 AC 98 ms
8,608 KB
testcase_14 AC 94 ms
8,536 KB
testcase_15 AC 94 ms
8,560 KB
testcase_16 AC 93 ms
8,560 KB
testcase_17 AC 93 ms
8,544 KB
testcase_18 AC 95 ms
8,760 KB
testcase_19 AC 88 ms
8,524 KB
testcase_20 AC 92 ms
8,636 KB
testcase_21 AC 93 ms
8,520 KB
testcase_22 AC 93 ms
8,568 KB
testcase_23 AC 89 ms
8,488 KB
testcase_24 AC 94 ms
8,640 KB
testcase_25 AC 96 ms
8,520 KB
testcase_26 AC 96 ms
8,600 KB
testcase_27 AC 92 ms
8,732 KB
testcase_28 AC 93 ms
8,536 KB
testcase_29 AC 99 ms
8,592 KB
testcase_30 AC 97 ms
8,592 KB
testcase_31 AC 98 ms
8,588 KB
testcase_32 AC 103 ms
8,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include "atcoder/all"
using namespace atcoder;
using Mint = modint998244353;

int N;
vector<vector<int>> G;
Mint ans = 0;

int maine(int now = 0, int par = -1) {
    int ret = 1;
    for (auto&& nxt : G[now]) {
        if (par == nxt)
            continue;
        ret += maine(nxt, now);
    }
    if (par != -1)
        ans += Mint{ret} * (ret - 1) + Mint{N - ret} * (N - ret - 1);
    return ret;
}

int main() {
    cin >> N;
    G.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    maine();
    cout << (ans / N / (N - 1) / (N - 1)).val() << endl;
}
0