結果
| 問題 |
No.1507 Road Blocked
|
| コンテスト | |
| ユーザー |
wolgnik
|
| 提出日時 | 2021-05-14 22:26:05 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 219 ms / 2,000 ms |
| コード長 | 718 bytes |
| コンパイル時間 | 211 ms |
| コンパイル使用メモリ | 82,168 KB |
| 実行使用メモリ | 97,024 KB |
| 最終ジャッジ日時 | 2024-10-02 02:04:13 |
| 合計ジャッジ時間 | 7,765 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
import sys
input = sys.stdin.readline
N = int(input())
e = [[] for _ in range(N + 1)]
for _ in range(N - 1):
u, v = map(int, input().split())
e[u].append(v)
e[v].append(u)
mod = 998244353
s = [1]
vis = [0] * (N + 1)
parent = [0] * (N + 1)
vis[1] = 1
order = []
while len(s):
x = s.pop()
order.append(x)
for y in e[x]:
if vis[y]: continue
parent[y] = x
vis[y] = 1
s.append(y)
size = [1] * (N + 1)
order.reverse()
for y in order[: -1]:
x = parent[y]
size[x] += size[y]
res = 0
for y in range(2, N + 1):
x = parent[y]
u = N - size[y]
d = size[y]
res += u * d
res %= mod
#print(y, u, d)
res *= pow(N * (N - 1) * (N - 1) // 2, mod - 2, mod)
res %= mod
print((1 - res) % mod)
wolgnik