結果

問題 No.1507 Road Blocked
ユーザー nasubi24nasubi24
提出日時 2021-05-14 22:42:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 182,776 KB
最終ジャッジ日時 2024-04-10 01:33:32
合計ジャッジ時間 12,437 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,776 KB
testcase_01 AC 40 ms
52,196 KB
testcase_02 AC 38 ms
52,756 KB
testcase_03 AC 317 ms
182,776 KB
testcase_04 AC 348 ms
100,704 KB
testcase_05 AC 349 ms
100,872 KB
testcase_06 AC 352 ms
100,884 KB
testcase_07 AC 347 ms
100,712 KB
testcase_08 AC 346 ms
101,088 KB
testcase_09 AC 355 ms
100,844 KB
testcase_10 AC 345 ms
100,932 KB
testcase_11 AC 351 ms
100,696 KB
testcase_12 AC 343 ms
100,640 KB
testcase_13 AC 349 ms
100,876 KB
testcase_14 AC 365 ms
100,680 KB
testcase_15 AC 348 ms
101,012 KB
testcase_16 AC 344 ms
100,612 KB
testcase_17 AC 355 ms
100,660 KB
testcase_18 AC 346 ms
100,700 KB
testcase_19 AC 344 ms
101,224 KB
testcase_20 AC 343 ms
100,560 KB
testcase_21 AC 348 ms
100,688 KB
testcase_22 AC 348 ms
100,688 KB
testcase_23 AC 352 ms
100,572 KB
testcase_24 AC 352 ms
100,736 KB
testcase_25 AC 354 ms
100,876 KB
testcase_26 AC 352 ms
100,832 KB
testcase_27 AC 350 ms
100,628 KB
testcase_28 AC 351 ms
100,528 KB
testcase_29 AC 361 ms
100,820 KB
testcase_30 AC 350 ms
100,964 KB
testcase_31 AC 345 ms
100,964 KB
testcase_32 AC 342 ms
100,740 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