結果

問題 No.1507 Road Blocked
ユーザー titiatitia
提出日時 2021-05-15 03:08:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 33,536 KB
最終ジャッジ日時 2024-04-10 08:12:41
合計ジャッジ時間 15,534 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,624 KB
testcase_01 AC 29 ms
10,624 KB
testcase_02 AC 29 ms
10,624 KB
testcase_03 AC 348 ms
33,536 KB
testcase_04 AC 451 ms
30,464 KB
testcase_05 AC 455 ms
30,592 KB
testcase_06 AC 461 ms
30,592 KB
testcase_07 AC 460 ms
30,464 KB
testcase_08 AC 451 ms
30,464 KB
testcase_09 AC 464 ms
30,464 KB
testcase_10 AC 465 ms
30,464 KB
testcase_11 AC 452 ms
30,592 KB
testcase_12 AC 446 ms
30,592 KB
testcase_13 AC 463 ms
30,464 KB
testcase_14 AC 455 ms
30,592 KB
testcase_15 AC 453 ms
30,592 KB
testcase_16 AC 445 ms
30,464 KB
testcase_17 AC 456 ms
30,592 KB
testcase_18 AC 443 ms
30,464 KB
testcase_19 AC 445 ms
30,464 KB
testcase_20 AC 451 ms
30,464 KB
testcase_21 AC 454 ms
30,464 KB
testcase_22 AC 448 ms
30,464 KB
testcase_23 AC 445 ms
30,592 KB
testcase_24 AC 439 ms
30,464 KB
testcase_25 AC 445 ms
30,720 KB
testcase_26 AC 445 ms
30,464 KB
testcase_27 AC 445 ms
30,464 KB
testcase_28 AC 453 ms
30,592 KB
testcase_29 AC 434 ms
30,592 KB
testcase_30 AC 446 ms
30,464 KB
testcase_31 AC 455 ms
30,464 KB
testcase_32 AC 445 ms
30,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
E=[[] for i in range(N)]

for i in range(N-1):
    x,y=map(int,input().split())
    x-=1
    y-=1
    E[x].append(y)
    E[y].append(x)

mod=998244353

ROOT=0

QUE=[ROOT] 
Parent=[-1]*(N+1)
Parent[ROOT]=N # ROOTの親を定めておく.
TOP_SORT=[] # トポロジカルソート

while QUE: # トポロジカルソートと同時に親を見つける
    x=QUE.pop()
    TOP_SORT.append(x)
    for to in E[x]:
        if Parent[to]==-1:
            Parent[to]=x
            QUE.append(to)

Children=[1]*(N+1)

for x in TOP_SORT[::-1]: #(自分を含む)子ノードの数を調べる
    Children[Parent[x]]+=Children[x]


ANS=0
for i in range(1,N):
    ANS+=Children[i]*(N-Children[i])

ANS=(1-ANS*pow(N-1,mod-2,mod)*pow(N*(N-1)//2,mod-2,mod))%mod

print(ANS)
0