結果
| 問題 |
No.1507 Road Blocked
|
| コンテスト | |
| ユーザー |
nonon
|
| 提出日時 | 2025-08-17 17:38:01 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 55 ms / 2,000 ms |
| コード長 | 955 bytes |
| コンパイル時間 | 3,124 ms |
| コンパイル使用メモリ | 285,664 KB |
| 実行使用メモリ | 13,824 KB |
| 最終ジャッジ日時 | 2025-08-17 17:38:09 |
| 合計ジャッジ時間 | 6,989 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; }
bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; }
#include <atcoder/modint>
using mint = atcoder::modint998244353;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<vector<int>> G(N);
for (int i = 1, u, v; i < N; i++) {
cin >> u >> v;
u--, v--;
G[u].push_back(v);
G[v].push_back(u);
}
vector<int> sub(N);
mint ans = 0;
auto dfs = [&] (auto dfs, int u, int p) -> void {
for (auto v : G[u]) {
if (v == p) continue;
dfs(dfs, v, u);
sub[u] += sub[v];
ans += mint(sub[v]) * (N - sub[v]);
}
sub[u]++;
};
dfs(dfs, 0, -1);
ans /= mint(N) * (N - 1) * (N - 1) / 2;
ans = 1 - ans;
cout << ans.val() << endl;
}
nonon