結果

問題 No.1507 Road Blocked
ユーザー wolgnikwolgnik
提出日時 2021-05-14 22:26:05
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 718 bytes
コンパイル時間 236 ms
使用メモリ 101,544 KB
最終ジャッジ日時 2022-11-25 19:21:31
合計ジャッジ時間 9,216 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 67 ms
75,736 KB
testcase_01 AC 66 ms
75,792 KB
testcase_02 AC 67 ms
75,672 KB
testcase_03 AC 144 ms
101,012 KB
testcase_04 AC 225 ms
101,160 KB
testcase_05 AC 227 ms
101,056 KB
testcase_06 AC 219 ms
101,208 KB
testcase_07 AC 228 ms
101,132 KB
testcase_08 AC 232 ms
101,544 KB
testcase_09 AC 237 ms
101,196 KB
testcase_10 AC 231 ms
101,072 KB
testcase_11 AC 225 ms
101,388 KB
testcase_12 AC 226 ms
101,416 KB
testcase_13 AC 226 ms
101,352 KB
testcase_14 AC 239 ms
101,052 KB
testcase_15 AC 222 ms
101,056 KB
testcase_16 AC 226 ms
101,068 KB
testcase_17 AC 223 ms
101,428 KB
testcase_18 AC 222 ms
101,136 KB
testcase_19 AC 225 ms
101,360 KB
testcase_20 AC 222 ms
101,360 KB
testcase_21 AC 222 ms
101,300 KB
testcase_22 AC 223 ms
101,168 KB
testcase_23 AC 218 ms
101,044 KB
testcase_24 AC 220 ms
101,060 KB
testcase_25 AC 229 ms
101,040 KB
testcase_26 AC 239 ms
101,176 KB
testcase_27 AC 240 ms
101,380 KB
testcase_28 AC 229 ms
101,236 KB
testcase_29 AC 220 ms
101,380 KB
testcase_30 AC 233 ms
101,176 KB
testcase_31 AC 233 ms
101,300 KB
testcase_32 AC 237 ms
101,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0