結果

問題 No.1507 Road Blocked
ユーザー nasubi24nasubi24
提出日時 2021-05-14 22:42:42
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 1,162 ms
使用メモリ 193,640 KB
最終ジャッジ日時 2022-11-25 20:01:53
合計ジャッジ時間 15,693 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 67 ms
75,536 KB
testcase_01 AC 66 ms
75,836 KB
testcase_02 AC 67 ms
75,760 KB
testcase_03 AC 426 ms
193,640 KB
testcase_04 AC 409 ms
112,336 KB
testcase_05 AC 404 ms
110,336 KB
testcase_06 AC 425 ms
111,532 KB
testcase_07 AC 427 ms
110,496 KB
testcase_08 AC 416 ms
110,972 KB
testcase_09 AC 415 ms
112,828 KB
testcase_10 AC 427 ms
110,876 KB
testcase_11 AC 441 ms
109,836 KB
testcase_12 AC 426 ms
110,100 KB
testcase_13 AC 429 ms
110,164 KB
testcase_14 AC 438 ms
111,300 KB
testcase_15 AC 424 ms
111,740 KB
testcase_16 AC 412 ms
111,036 KB
testcase_17 AC 420 ms
109,900 KB
testcase_18 AC 418 ms
110,012 KB
testcase_19 AC 428 ms
110,396 KB
testcase_20 AC 421 ms
110,424 KB
testcase_21 AC 427 ms
109,660 KB
testcase_22 AC 420 ms
110,976 KB
testcase_23 AC 425 ms
109,652 KB
testcase_24 AC 436 ms
111,160 KB
testcase_25 AC 433 ms
109,972 KB
testcase_26 AC 435 ms
109,832 KB
testcase_27 AC 432 ms
110,568 KB
testcase_28 AC 418 ms
109,376 KB
testcase_29 AC 438 ms
111,080 KB
testcase_30 AC 431 ms
109,764 KB
testcase_31 AC 422 ms
110,312 KB
testcase_32 AC 423 ms
110,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
n=int(input())
mod=998244353
q=pow((n-1)*(n-1)*n//2,mod-2,mod)
path=[[] for _ in range(n)]
p2=[]
for i in range(n-1):
    a,b=map(int,input().split())
    path[a-1].append(b-1)
    path[b-1].append(a-1)
    p2.append([a-1,b-1])
s=[1]*n
seen=[False]*n
def dfs(t):
    global seen,s
    for i in path[t]:
        if not seen[i]:
            seen[i]=True
            s[t]+=dfs(i)
    return s[t]
seen[0]=True
s[0]=dfs(0)
p=0
m=(n-1)*n//2
for i in p2:
    t=min(s[i[0]],s[i[1]])
    p+=m-t*(n-t)
print(p*q%mod)
0