結果

問題 No.1507 Road Blocked
ユーザー oliverx3oliverx3
提出日時 2021-05-13 09:45:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,158 bytes
コンパイル時間 4,596 ms
コンパイル使用メモリ 265,308 KB
実行使用メモリ 17,172 KB
最終ジャッジ日時 2023-10-25 03:48:31
合計ジャッジ時間 9,028 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,416 KB
testcase_01 AC 3 ms
6,416 KB
testcase_02 AC 3 ms
6,416 KB
testcase_03 AC 76 ms
17,172 KB
testcase_04 AC 98 ms
10,928 KB
testcase_05 AC 100 ms
10,928 KB
testcase_06 AC 102 ms
10,928 KB
testcase_07 AC 100 ms
10,928 KB
testcase_08 AC 104 ms
10,928 KB
testcase_09 AC 104 ms
10,928 KB
testcase_10 AC 101 ms
10,928 KB
testcase_11 AC 103 ms
10,928 KB
testcase_12 AC 101 ms
10,928 KB
testcase_13 AC 101 ms
10,928 KB
testcase_14 AC 100 ms
10,928 KB
testcase_15 AC 99 ms
10,928 KB
testcase_16 AC 99 ms
10,928 KB
testcase_17 AC 103 ms
10,928 KB
testcase_18 AC 99 ms
10,928 KB
testcase_19 AC 100 ms
10,928 KB
testcase_20 AC 99 ms
10,928 KB
testcase_21 AC 101 ms
10,928 KB
testcase_22 AC 101 ms
10,928 KB
testcase_23 AC 105 ms
10,928 KB
testcase_24 AC 106 ms
10,928 KB
testcase_25 AC 104 ms
10,928 KB
testcase_26 AC 100 ms
10,928 KB
testcase_27 AC 97 ms
10,928 KB
testcase_28 AC 95 ms
10,928 KB
testcase_29 AC 98 ms
10,928 KB
testcase_30 AC 99 ms
10,928 KB
testcase_31 AC 98 ms
10,928 KB
testcase_32 AC 99 ms
10,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using mint = atcoder::modint998244353;

mint dp[100010];

std::vector<int> G[100010];
bool seen[100010];

int dfs(int node = 0) {
    for(const auto &to:G[node]) {
        if(seen[to]) continue;
        seen[to] = true;
        dp[node] += dfs(to);
    }
    return (++dp[node]).val();
}

int main() {
    long long n;
    std::cin >> n;
    std::vector<std::pair<long long, long long>> v(n-1);
    rep(i, n-1) {
        int a, b;
        std::cin >> a >> b;
        a--, b--;
        v[i] = {a, b};
        G[a].push_back(b);
        G[b].push_back(a);
    }
    seen[0] = true;
    dfs();
    //rep(i, n) std::cout << dp[i].val() << ' ';std::endl(std::cout);
    mint ans = 0;
    for(auto [a, b]:v) {
        if(dp[a].val()<dp[b].val()) std::swap(a, b);
        ans += (n-dp[b])*dp[b];
        //std::cout << (dp[a]-dp[b]).val() << ' ' << dp[b].val() << std::endl;
    }
    //rep(i, n) ans += dp[i]*(n-dp[i]);
    //std::cout << ans.val() << std::endl;
    ans/=(n-1)*n*(n-1)/2;
    ans = 1-ans;
    std::cout << ans.val() << std::endl;
    return 0;
}
0