結果

問題 No.1507 Road Blocked
ユーザー convexineqconvexineq
提出日時 2021-05-14 22:39:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,848 KB
実行使用メモリ 96,624 KB
最終ジャッジ日時 2024-04-10 01:24:19
合計ジャッジ時間 7,575 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,504 KB
testcase_01 AC 39 ms
52,544 KB
testcase_02 AC 36 ms
53,060 KB
testcase_03 AC 142 ms
95,744 KB
testcase_04 AC 204 ms
96,312 KB
testcase_05 AC 202 ms
96,072 KB
testcase_06 AC 196 ms
96,140 KB
testcase_07 AC 196 ms
96,160 KB
testcase_08 AC 193 ms
96,220 KB
testcase_09 AC 196 ms
96,228 KB
testcase_10 AC 192 ms
96,148 KB
testcase_11 AC 200 ms
95,972 KB
testcase_12 AC 193 ms
95,916 KB
testcase_13 AC 254 ms
96,100 KB
testcase_14 AC 194 ms
96,220 KB
testcase_15 AC 190 ms
96,024 KB
testcase_16 AC 185 ms
96,020 KB
testcase_17 AC 192 ms
96,272 KB
testcase_18 AC 192 ms
96,624 KB
testcase_19 AC 195 ms
96,108 KB
testcase_20 AC 200 ms
96,004 KB
testcase_21 AC 197 ms
96,304 KB
testcase_22 AC 197 ms
96,280 KB
testcase_23 AC 198 ms
96,240 KB
testcase_24 AC 197 ms
96,092 KB
testcase_25 AC 198 ms
95,960 KB
testcase_26 AC 196 ms
96,236 KB
testcase_27 AC 196 ms
95,908 KB
testcase_28 AC 209 ms
96,284 KB
testcase_29 AC 200 ms
96,028 KB
testcase_30 AC 214 ms
96,172 KB
testcase_31 AC 205 ms
95,912 KB
testcase_32 AC 197 ms
95,904 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