結果

問題 No.1507 Road Blocked
ユーザー GER_chenGER_chen
提出日時 2021-05-14 22:44:16
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 412 ms / 2,000 ms
コード長 640 bytes
コンパイル時間 327 ms
使用メモリ 118,032 KB
最終ジャッジ日時 2022-11-25 20:18:16
合計ジャッジ時間 12,647 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 59 ms
75,888 KB
testcase_01 AC 59 ms
75,864 KB
testcase_02 AC 57 ms
75,764 KB
testcase_03 AC 237 ms
116,872 KB
testcase_04 AC 353 ms
117,100 KB
testcase_05 AC 340 ms
117,212 KB
testcase_06 AC 349 ms
116,948 KB
testcase_07 AC 340 ms
117,076 KB
testcase_08 AC 349 ms
116,964 KB
testcase_09 AC 348 ms
118,032 KB
testcase_10 AC 345 ms
117,152 KB
testcase_11 AC 351 ms
117,148 KB
testcase_12 AC 331 ms
117,156 KB
testcase_13 AC 347 ms
116,944 KB
testcase_14 AC 344 ms
116,904 KB
testcase_15 AC 342 ms
117,316 KB
testcase_16 AC 335 ms
117,124 KB
testcase_17 AC 348 ms
117,300 KB
testcase_18 AC 343 ms
117,108 KB
testcase_19 AC 347 ms
117,144 KB
testcase_20 AC 347 ms
117,348 KB
testcase_21 AC 341 ms
117,364 KB
testcase_22 AC 354 ms
116,584 KB
testcase_23 AC 336 ms
117,824 KB
testcase_24 AC 350 ms
117,564 KB
testcase_25 AC 348 ms
117,840 KB
testcase_26 AC 339 ms
116,868 KB
testcase_27 AC 390 ms
117,124 KB
testcase_28 AC 412 ms
117,028 KB
testcase_29 AC 340 ms
116,704 KB
testcase_30 AC 345 ms
117,184 KB
testcase_31 AC 340 ms
116,756 KB
testcase_32 AC 342 ms
117,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
n = int(input())
Adj = [set() for _ in range(n)]
for _ in range(n-1):
    u, v = map(int, input().split())
    Adj[u-1].add(v-1)
    Adj[v-1].add(u-1)
Parent = [-1]*n
Size = [0]*n
D = [0]
Sort = []
while D:
    v = D.pop()
    Sort.append(v)
    for nxt in Adj[v]:
        if nxt != Parent[v]:
            Parent[nxt] = v
            D.append(nxt)

for i in Sort[::-1]:
    Size[i] += 1
    for child in Adj[i]:
        if child != Parent[i]:
            Size[i] += Size[child]

ans = 0
cff = pow((n*(n-1)**2)//2, mod-2, mod)
for i in range(1, n):
    s = Size[i]
    ans += s*(n-s)
    ans %= mod
print((mod+1-ans*cff)%mod)
0