結果

問題 No.1507 Road Blocked
ユーザー Akijin_007Akijin_007
提出日時 2023-05-12 11:36:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 322 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 187,424 KB
最終ジャッジ日時 2023-08-18 20:27:37
合計ジャッジ時間 12,021 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
71,396 KB
testcase_01 AC 61 ms
71,248 KB
testcase_02 AC 63 ms
71,524 KB
testcase_03 AC 317 ms
187,424 KB
testcase_04 AC 322 ms
100,444 KB
testcase_05 AC 310 ms
99,328 KB
testcase_06 AC 295 ms
100,924 KB
testcase_07 AC 305 ms
100,932 KB
testcase_08 AC 299 ms
99,876 KB
testcase_09 AC 313 ms
100,700 KB
testcase_10 AC 305 ms
100,116 KB
testcase_11 AC 306 ms
99,124 KB
testcase_12 AC 303 ms
100,220 KB
testcase_13 AC 306 ms
99,020 KB
testcase_14 AC 317 ms
100,488 KB
testcase_15 AC 299 ms
100,172 KB
testcase_16 AC 301 ms
100,092 KB
testcase_17 AC 297 ms
99,724 KB
testcase_18 AC 306 ms
98,540 KB
testcase_19 AC 309 ms
99,840 KB
testcase_20 AC 315 ms
100,060 KB
testcase_21 AC 296 ms
99,136 KB
testcase_22 AC 307 ms
100,856 KB
testcase_23 AC 300 ms
98,936 KB
testcase_24 AC 306 ms
99,148 KB
testcase_25 AC 302 ms
98,672 KB
testcase_26 AC 316 ms
98,572 KB
testcase_27 AC 319 ms
100,940 KB
testcase_28 AC 314 ms
98,580 KB
testcase_29 AC 312 ms
99,172 KB
testcase_30 AC 305 ms
99,184 KB
testcase_31 AC 304 ms
99,712 KB
testcase_32 AC 301 ms
99,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(200000)

N = int(input())
mod = 998244353

to = [[] for i in range(N)]
e = []
for i in range(N-1):
    u, v = list(map(int, input().split()))
    to[u-1].append(v-1)
    to[v-1].append(u-1)
    e.append((u-1, v-1))

a = [-1] * N
b = [-1] * N

time = 0

def DFS(x):
    global time
    global a
    global b
    a[x] = time
    time += 1

    for y in to[x]:
        if a[y] == -1:
            DFS(y)

    b[x] = time
    time += 1

DFS(0)
# print(a)
# print(b)

ans = 0
for i in range(N-1):
    s, t = e[i]
    m = min((b[s]-a[s]+1)//2, (b[t]-a[t]+1)//2)

    ans = (ans + m*(N-m)) % mod
    # print(m, ans)

u = (N * (N-1) * (N-1) // 2) % mod
ans = (ans * pow(u, mod-2, mod))
print((1 - ans) % mod)
0