結果

問題 No.1507 Road Blocked
ユーザー oliverx3
提出日時 2021-05-13 09:03:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 764 bytes
コンパイル時間 3,967 ms
コンパイル使用メモリ 252,536 KB
最終ジャッジ日時 2025-01-21 10:25:31
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other WA * 30
権限があれば一括ダウンロードができます

ソースコード

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];

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

int main() {
    int n;
    std::cin >> n;
    rep(i, n-1) {
        int a, b;
        std::cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dp[0] = 1;
    dfs();
    mint ans = 0;
    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