結果

問題 No.1507 Road Blocked
ユーザー kwm_tkwm_t
提出日時 2021-05-15 10:38:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,408 bytes
コンパイル時間 3,387 ms
コンパイル使用メモリ 225,700 KB
実行使用メモリ 17,616 KB
最終ジャッジ日時 2024-04-10 15:07:12
合計ジャッジ時間 7,264 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,172 KB
testcase_01 AC 5 ms
8,300 KB
testcase_02 AC 4 ms
8,248 KB
testcase_03 AC 35 ms
17,616 KB
testcase_04 AC 39 ms
11,536 KB
testcase_05 AC 42 ms
11,428 KB
testcase_06 AC 43 ms
11,540 KB
testcase_07 AC 39 ms
11,472 KB
testcase_08 AC 40 ms
11,392 KB
testcase_09 AC 39 ms
11,488 KB
testcase_10 AC 39 ms
11,300 KB
testcase_11 AC 37 ms
11,472 KB
testcase_12 AC 40 ms
11,352 KB
testcase_13 AC 40 ms
11,500 KB
testcase_14 AC 39 ms
11,600 KB
testcase_15 AC 39 ms
11,436 KB
testcase_16 AC 40 ms
11,328 KB
testcase_17 AC 39 ms
11,464 KB
testcase_18 AC 39 ms
11,436 KB
testcase_19 AC 41 ms
11,304 KB
testcase_20 AC 38 ms
11,316 KB
testcase_21 AC 38 ms
11,432 KB
testcase_22 AC 38 ms
11,420 KB
testcase_23 AC 38 ms
11,436 KB
testcase_24 AC 39 ms
11,456 KB
testcase_25 AC 40 ms
11,452 KB
testcase_26 AC 37 ms
11,424 KB
testcase_27 AC 39 ms
11,492 KB
testcase_28 AC 39 ms
11,552 KB
testcase_29 AC 38 ms
11,328 KB
testcase_30 AC 39 ms
11,588 KB
testcase_31 AC 39 ms
11,532 KB
testcase_32 AC 39 ms
11,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include "atcoder/all"
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

long long n;
mint ans = 0;
vector<int>to[200005];
int dfs(int v, int d = 0, int p = -1) {
	int sum = 0;
	for (int e : to[v]) {
		if (p == e) continue;
		//処理
		int count = dfs(e, d + 1, v);
		ans += n * (n - 1) / 2 - (n - count) * count;
		sum += count;
	}
	return sum + 1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	dfs(0);
	ans /= (n*(n - 1) / 2);
	ans /= (n - 1);
	cout << ans.val() << endl;
	return 0;
}
0