結果

問題 No.1507 Road Blocked
ユーザー Akijin_007
提出日時 2023-05-12 11:35:38
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 765 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 98,768 KB
最終ジャッジ日時 2024-11-28 04:13:00
合計ジャッジ時間 13,050 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 RE * 1
権限があれば一括ダウンロードができます

ソースコード

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