結果

問題 No.1507 Road Blocked
ユーザー brthyyjpbrthyyjp
提出日時 2021-05-18 21:02:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 763 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 96,688 KB
最終ジャッジ日時 2024-04-17 08:08:36
合計ジャッジ時間 7,922 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,224 KB
testcase_01 AC 46 ms
52,096 KB
testcase_02 AC 50 ms
51,968 KB
testcase_03 AC 113 ms
91,460 KB
testcase_04 AC 214 ms
96,412 KB
testcase_05 AC 212 ms
95,920 KB
testcase_06 AC 205 ms
96,176 KB
testcase_07 AC 209 ms
96,668 KB
testcase_08 AC 206 ms
96,432 KB
testcase_09 AC 212 ms
96,180 KB
testcase_10 AC 212 ms
95,908 KB
testcase_11 AC 204 ms
96,044 KB
testcase_12 AC 211 ms
95,912 KB
testcase_13 AC 200 ms
96,052 KB
testcase_14 AC 205 ms
96,432 KB
testcase_15 AC 202 ms
96,676 KB
testcase_16 AC 204 ms
96,428 KB
testcase_17 AC 207 ms
96,296 KB
testcase_18 AC 204 ms
96,340 KB
testcase_19 AC 213 ms
95,916 KB
testcase_20 AC 209 ms
96,688 KB
testcase_21 AC 210 ms
96,288 KB
testcase_22 AC 212 ms
96,036 KB
testcase_23 AC 208 ms
96,484 KB
testcase_24 AC 206 ms
96,176 KB
testcase_25 AC 213 ms
96,432 KB
testcase_26 AC 215 ms
96,032 KB
testcase_27 AC 206 ms
92,968 KB
testcase_28 AC 212 ms
96,420 KB
testcase_29 AC 207 ms
96,420 KB
testcase_30 AC 213 ms
95,928 KB
testcase_31 AC 211 ms
95,912 KB
testcase_32 AC 205 ms
96,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n = int(input())
mod = 998244353
g = [[] for i in range(n)]
for i in range(n-1):
    u, v = map(int, input().split())
    u, v = u-1, v-1
    g[u].append(v)
    g[v].append(u)

s = []
parent = [-1]*n
order = []
s.append(0)
while s:
    v = s.pop()
    order.append(v)
    for u in g[v]:
        if parent[v] == u:
            continue
        s.append(u)
        parent[u] = v
#print(order)
order.reverse()
C = [1]*n
for v in order:
    if parent[v] != -1:
        C[parent[v]] += C[v]
#print(C)
p = 0
for v in order:
    if parent[v] != -1:
        p += C[v]*(C[v]-1)//2
        p += (n-C[v])*(n-C[v]-1)//2
q = n*(n-1)//2
q *= (n-1)
k = p*pow(q, mod-2, mod)
k %= mod
print(k)
0