結果

問題 No.1507 Road Blocked
ユーザー Akijin_007Akijin_007
提出日時 2023-05-12 11:35:38
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 765 bytes
コンパイル時間 741 ms
コンパイル使用メモリ 85,764 KB
実行使用メモリ 102,832 KB
最終ジャッジ日時 2023-08-18 20:25:32
合計ジャッジ時間 13,280 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,212 KB
testcase_01 AC 67 ms
71,184 KB
testcase_02 AC 68 ms
71,192 KB
testcase_03 RE -
testcase_04 AC 315 ms
100,292 KB
testcase_05 AC 312 ms
99,196 KB
testcase_06 AC 298 ms
100,536 KB
testcase_07 AC 303 ms
100,744 KB
testcase_08 AC 300 ms
99,500 KB
testcase_09 AC 322 ms
100,512 KB
testcase_10 AC 301 ms
99,788 KB
testcase_11 AC 307 ms
98,604 KB
testcase_12 AC 312 ms
100,148 KB
testcase_13 AC 310 ms
99,044 KB
testcase_14 AC 312 ms
100,072 KB
testcase_15 AC 294 ms
100,204 KB
testcase_16 AC 301 ms
99,568 KB
testcase_17 AC 302 ms
99,680 KB
testcase_18 AC 335 ms
98,724 KB
testcase_19 AC 313 ms
99,200 KB
testcase_20 AC 299 ms
99,632 KB
testcase_21 AC 314 ms
98,588 KB
testcase_22 AC 316 ms
100,656 KB
testcase_23 AC 305 ms
98,736 KB
testcase_24 AC 321 ms
99,016 KB
testcase_25 AC 315 ms
98,212 KB
testcase_26 AC 310 ms
98,448 KB
testcase_27 AC 324 ms
100,480 KB
testcase_28 AC 306 ms
98,832 KB
testcase_29 AC 301 ms
98,512 KB
testcase_30 AC 320 ms
98,972 KB
testcase_31 AC 328 ms
99,564 KB
testcase_32 AC 310 ms
100,096 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