結果

問題 No.1507 Road Blocked
ユーザー convexineqconvexineq
提出日時 2021-05-14 22:39:24
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 300 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 214 ms
使用メモリ 103,084 KB
最終ジャッジ日時 2022-11-25 19:52:02
合計ジャッジ時間 11,461 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 70 ms
75,744 KB
testcase_01 AC 68 ms
75,952 KB
testcase_02 AC 67 ms
75,504 KB
testcase_03 AC 217 ms
98,856 KB
testcase_04 AC 277 ms
102,892 KB
testcase_05 AC 281 ms
102,796 KB
testcase_06 AC 275 ms
102,792 KB
testcase_07 AC 300 ms
102,936 KB
testcase_08 AC 290 ms
102,864 KB
testcase_09 AC 297 ms
102,768 KB
testcase_10 AC 277 ms
103,028 KB
testcase_11 AC 282 ms
103,056 KB
testcase_12 AC 291 ms
102,780 KB
testcase_13 AC 274 ms
103,052 KB
testcase_14 AC 282 ms
102,792 KB
testcase_15 AC 285 ms
102,804 KB
testcase_16 AC 290 ms
103,048 KB
testcase_17 AC 277 ms
103,084 KB
testcase_18 AC 278 ms
103,068 KB
testcase_19 AC 287 ms
102,860 KB
testcase_20 AC 277 ms
103,008 KB
testcase_21 AC 282 ms
102,800 KB
testcase_22 AC 286 ms
103,016 KB
testcase_23 AC 275 ms
102,520 KB
testcase_24 AC 275 ms
102,556 KB
testcase_25 AC 281 ms
102,816 KB
testcase_26 AC 281 ms
102,832 KB
testcase_27 AC 280 ms
102,556 KB
testcase_28 AC 285 ms
102,552 KB
testcase_29 AC 274 ms
103,008 KB
testcase_30 AC 275 ms
102,508 KB
testcase_31 AC 281 ms
103,016 KB
testcase_32 AC 277 ms
102,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
 
order = []
st = [0]
parent = [-1]*n
while st:
    v = st.pop()
    order.append(v)
    for c in g[v]:
        if c != parent[v]:
            st.append(c)
            parent[c] = v

size = [1]*n
for i in order[::-1]:
    if i==0: break
    size[parent[i]] += size[i]
    
v = 0
for i in range(n):
    v += size[i]*(n-size[i])

MOD = 998244353
c = n*(n-1)*(n-1)//2%MOD
p = v*pow(c,MOD-2,MOD)%MOD
print((1-p)%MOD)
0