結果

問題 No.1507 Road Blocked
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-05-14 22:33:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 299 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,268 KB
実行使用メモリ 177,616 KB
最終ジャッジ日時 2024-04-10 01:08:58
合計ジャッジ時間 10,562 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,532 KB
testcase_01 AC 40 ms
53,776 KB
testcase_02 AC 41 ms
52,720 KB
testcase_03 AC 288 ms
177,616 KB
testcase_04 AC 286 ms
89,220 KB
testcase_05 AC 291 ms
89,324 KB
testcase_06 AC 280 ms
89,240 KB
testcase_07 AC 293 ms
89,608 KB
testcase_08 AC 281 ms
89,284 KB
testcase_09 AC 285 ms
89,148 KB
testcase_10 AC 282 ms
89,192 KB
testcase_11 AC 289 ms
89,304 KB
testcase_12 AC 279 ms
88,864 KB
testcase_13 AC 285 ms
89,172 KB
testcase_14 AC 294 ms
89,048 KB
testcase_15 AC 287 ms
89,452 KB
testcase_16 AC 280 ms
89,264 KB
testcase_17 AC 291 ms
89,308 KB
testcase_18 AC 297 ms
88,764 KB
testcase_19 AC 299 ms
89,728 KB
testcase_20 AC 280 ms
89,308 KB
testcase_21 AC 291 ms
88,984 KB
testcase_22 AC 293 ms
89,108 KB
testcase_23 AC 296 ms
89,024 KB
testcase_24 AC 294 ms
89,380 KB
testcase_25 AC 288 ms
89,460 KB
testcase_26 AC 286 ms
88,972 KB
testcase_27 AC 286 ms
89,200 KB
testcase_28 AC 280 ms
89,196 KB
testcase_29 AC 288 ms
89,264 KB
testcase_30 AC 281 ms
88,908 KB
testcase_31 AC 285 ms
89,200 KB
testcase_32 AC 270 ms
89,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(2*10**5)
n = int(input())
e = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)

mod = 998244353
count = [0]*n
def dfs(x,p=-1):
    c = 1
    for nex in e[x]:
        if nex == p:
            continue
        c += dfs(nex,x)
    count[x] = c
    return c

dfs(0,-1)
all = n*(n-1)//2*(n-1)
ans = all
for i in range(n):
    for j in e[i]:
        if count[j] > count[i]:
            continue
        ans -= count[j]*(n-count[j])

m = pow(all,mod-2,mod)
print(ans*m%mod)
0