結果

問題 No.1507 Road Blocked
ユーザー 👑 rin204rin204
提出日時 2022-01-27 00:37:02
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 286 ms / 2,000 ms
コード長 569 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 182,360 KB
最終ジャッジ日時 2023-08-25 14:03:16
合計ジャッジ時間 13,678 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,296 KB
testcase_01 AC 60 ms
71,092 KB
testcase_02 AC 61 ms
71,112 KB
testcase_03 AC 286 ms
182,360 KB
testcase_04 AC 230 ms
91,416 KB
testcase_05 AC 237 ms
90,552 KB
testcase_06 AC 228 ms
91,028 KB
testcase_07 AC 247 ms
91,576 KB
testcase_08 AC 237 ms
91,096 KB
testcase_09 AC 249 ms
90,104 KB
testcase_10 AC 244 ms
91,224 KB
testcase_11 AC 266 ms
90,532 KB
testcase_12 AC 258 ms
90,572 KB
testcase_13 AC 264 ms
90,712 KB
testcase_14 AC 280 ms
91,192 KB
testcase_15 AC 261 ms
90,436 KB
testcase_16 AC 262 ms
90,536 KB
testcase_17 AC 280 ms
90,668 KB
testcase_18 AC 257 ms
89,920 KB
testcase_19 AC 255 ms
92,840 KB
testcase_20 AC 239 ms
91,440 KB
testcase_21 AC 236 ms
89,592 KB
testcase_22 AC 253 ms
90,792 KB
testcase_23 AC 248 ms
90,096 KB
testcase_24 AC 243 ms
90,540 KB
testcase_25 AC 255 ms
91,284 KB
testcase_26 AC 268 ms
90,508 KB
testcase_27 AC 257 ms
90,284 KB
testcase_28 AC 248 ms
90,360 KB
testcase_29 AC 264 ms
90,724 KB
testcase_30 AC 247 ms
90,104 KB
testcase_31 AC 274 ms
92,132 KB
testcase_32 AC 259 ms
91,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 9)
MOD = 998244353

n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

ans = 0

def dfs(pos, bpos):
    global ans
    ret = 1
    for npos in edges[pos]:
        if npos == bpos:
            continue
        ret += dfs(npos, pos)
    if pos != 0:
        ans += n * (n - 1) // 2 - ret * (n - ret)
    return ret
    
dfs(0, -1)
div = n * (n - 1) // 2 * (n - 1)
print(ans * pow(div, MOD - 2, MOD) % MOD)
0