結果

問題 No.1507 Road Blocked
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-05-14 22:33:09
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 428 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 272 ms
使用メモリ 171,832 KB
最終ジャッジ日時 2022-11-25 19:37:37
合計ジャッジ時間 14,252 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 72 ms
75,472 KB
testcase_01 AC 69 ms
75,768 KB
testcase_02 AC 69 ms
75,644 KB
testcase_03 AC 379 ms
171,832 KB
testcase_04 AC 391 ms
98,432 KB
testcase_05 AC 403 ms
97,228 KB
testcase_06 AC 428 ms
97,552 KB
testcase_07 AC 401 ms
98,748 KB
testcase_08 AC 383 ms
97,436 KB
testcase_09 AC 381 ms
96,808 KB
testcase_10 AC 383 ms
98,160 KB
testcase_11 AC 389 ms
98,280 KB
testcase_12 AC 357 ms
96,904 KB
testcase_13 AC 350 ms
96,904 KB
testcase_14 AC 351 ms
98,272 KB
testcase_15 AC 367 ms
97,304 KB
testcase_16 AC 410 ms
96,984 KB
testcase_17 AC 374 ms
97,356 KB
testcase_18 AC 357 ms
96,792 KB
testcase_19 AC 400 ms
99,828 KB
testcase_20 AC 355 ms
97,908 KB
testcase_21 AC 382 ms
96,456 KB
testcase_22 AC 355 ms
97,284 KB
testcase_23 AC 345 ms
96,884 KB
testcase_24 AC 342 ms
97,144 KB
testcase_25 AC 361 ms
97,420 KB
testcase_26 AC 399 ms
96,616 KB
testcase_27 AC 378 ms
97,316 KB
testcase_28 AC 369 ms
96,648 KB
testcase_29 AC 404 ms
97,664 KB
testcase_30 AC 355 ms
96,804 KB
testcase_31 AC 364 ms
98,352 KB
testcase_32 AC 381 ms
97,892 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