結果

問題 No.1507 Road Blocked
ユーザー Akijin_007Akijin_007
提出日時 2023-05-11 20:57:15
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 765 bytes
コンパイル時間 1,468 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 103,744 KB
最終ジャッジ日時 2023-08-18 12:16:35
合計ジャッジ時間 15,570 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,164 KB
testcase_01 AC 75 ms
71,376 KB
testcase_02 AC 72 ms
71,172 KB
testcase_03 RE -
testcase_04 AC 353 ms
100,496 KB
testcase_05 AC 349 ms
99,304 KB
testcase_06 AC 340 ms
100,616 KB
testcase_07 AC 346 ms
100,760 KB
testcase_08 AC 339 ms
99,312 KB
testcase_09 AC 346 ms
100,580 KB
testcase_10 AC 340 ms
100,192 KB
testcase_11 AC 346 ms
98,860 KB
testcase_12 AC 341 ms
100,044 KB
testcase_13 AC 343 ms
99,032 KB
testcase_14 AC 351 ms
100,588 KB
testcase_15 AC 346 ms
99,952 KB
testcase_16 AC 350 ms
100,036 KB
testcase_17 AC 344 ms
99,612 KB
testcase_18 AC 346 ms
98,604 KB
testcase_19 AC 350 ms
99,720 KB
testcase_20 AC 348 ms
99,872 KB
testcase_21 AC 341 ms
98,776 KB
testcase_22 AC 354 ms
100,908 KB
testcase_23 AC 344 ms
99,116 KB
testcase_24 AC 351 ms
99,060 KB
testcase_25 AC 342 ms
98,264 KB
testcase_26 AC 348 ms
98,548 KB
testcase_27 AC 339 ms
100,504 KB
testcase_28 AC 336 ms
98,484 KB
testcase_29 AC 342 ms
98,984 KB
testcase_30 AC 338 ms
99,140 KB
testcase_31 AC 342 ms
99,596 KB
testcase_32 AC 341 ms
99,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#int(input())
#map(int, input().split())
#list(map(int, input().split()))

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