結果

問題 No.1507 Road Blocked
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-14 22:33:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 4,724 ms
コンパイル使用メモリ 255,724 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-04-10 01:09:58
合計ジャッジ時間 8,699 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 75 ms
13,312 KB
testcase_04 AC 104 ms
8,704 KB
testcase_05 AC 103 ms
8,832 KB
testcase_06 AC 102 ms
8,960 KB
testcase_07 AC 105 ms
8,832 KB
testcase_08 AC 97 ms
8,704 KB
testcase_09 AC 101 ms
8,704 KB
testcase_10 AC 101 ms
8,704 KB
testcase_11 AC 95 ms
8,780 KB
testcase_12 AC 100 ms
8,704 KB
testcase_13 AC 96 ms
8,720 KB
testcase_14 AC 101 ms
8,704 KB
testcase_15 AC 99 ms
8,832 KB
testcase_16 AC 99 ms
8,704 KB
testcase_17 AC 96 ms
8,832 KB
testcase_18 AC 99 ms
8,960 KB
testcase_19 AC 98 ms
8,960 KB
testcase_20 AC 100 ms
8,960 KB
testcase_21 AC 104 ms
8,704 KB
testcase_22 AC 103 ms
8,704 KB
testcase_23 AC 98 ms
8,832 KB
testcase_24 AC 99 ms
8,704 KB
testcase_25 AC 95 ms
8,832 KB
testcase_26 AC 100 ms
8,832 KB
testcase_27 AC 99 ms
8,704 KB
testcase_28 AC 98 ms
8,704 KB
testcase_29 AC 96 ms
8,832 KB
testcase_30 AC 95 ms
8,704 KB
testcase_31 AC 99 ms
8,832 KB
testcase_32 AC 94 ms
8,832 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