結果

問題 No.1507 Road Blocked
ユーザー seven_threeseven_three
提出日時 2021-05-16 05:41:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,113 bytes
コンパイル時間 4,002 ms
コンパイル使用メモリ 96,240 KB
実行使用メモリ 14,820 KB
最終ジャッジ日時 2023-07-27 11:29:41
合計ジャッジ時間 8,309 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,244 KB
testcase_01 AC 3 ms
5,428 KB
testcase_02 AC 3 ms
5,248 KB
testcase_03 AC 69 ms
14,820 KB
testcase_04 AC 91 ms
8,640 KB
testcase_05 AC 92 ms
8,588 KB
testcase_06 AC 93 ms
8,732 KB
testcase_07 AC 91 ms
8,588 KB
testcase_08 AC 91 ms
8,592 KB
testcase_09 AC 90 ms
8,520 KB
testcase_10 AC 92 ms
8,652 KB
testcase_11 AC 90 ms
8,696 KB
testcase_12 AC 92 ms
8,536 KB
testcase_13 AC 91 ms
8,616 KB
testcase_14 AC 90 ms
8,624 KB
testcase_15 AC 93 ms
8,692 KB
testcase_16 AC 92 ms
8,620 KB
testcase_17 AC 90 ms
8,548 KB
testcase_18 AC 91 ms
8,484 KB
testcase_19 AC 89 ms
8,656 KB
testcase_20 AC 91 ms
8,708 KB
testcase_21 AC 92 ms
8,532 KB
testcase_22 AC 96 ms
8,652 KB
testcase_23 AC 92 ms
8,640 KB
testcase_24 AC 92 ms
8,616 KB
testcase_25 AC 91 ms
8,480 KB
testcase_26 AC 94 ms
8,544 KB
testcase_27 AC 91 ms
8,588 KB
testcase_28 AC 89 ms
8,608 KB
testcase_29 AC 93 ms
8,584 KB
testcase_30 AC 91 ms
8,536 KB
testcase_31 AC 89 ms
8,548 KB
testcase_32 AC 93 ms
8,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long n;
vector<vector<int>> vec(100010);
bool bo[100010] = { false }, bo1[100010] = { true };
long long mod = 998244353, ans = 0;
long long dfs(int now, int mem) {
	long long sum = 0;
	for (int i = 0; i < vec[now].size(); i++) {
		if (vec[now][i] == mem)continue;
		sum += dfs(vec[now][i], now);
	}
	ans += (sum + 1) * (n - sum - 1);
	return sum + 1;
}
long long m_pow(long long x, long long y) {
	long long ans = 1;
	while (y > 0) {
		if ((y & 1) == 1) {
			ans = ans * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}
int main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		vec[a].emplace_back(b);
		vec[b].emplace_back(a);
	}
	dfs(1, -1);
	ans = n * (n - 1) / 2 * (n - 1) - ans;
	ans %= mod;
	cout << ans * m_pow(n * (n - 1) / 2 * (n - 1) % mod, mod - 2) % mod << endl;
}
0