結果

問題 No.1507 Road Blocked
ユーザー raven7959raven7959
提出日時 2021-09-24 08:54:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 388 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 200,992 KB
最終ジャッジ日時 2023-09-18 20:10:14
合計ジャッジ時間 13,188 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,428 KB
testcase_01 AC 72 ms
71,304 KB
testcase_02 AC 72 ms
71,416 KB
testcase_03 AC 361 ms
200,992 KB
testcase_04 AC 322 ms
97,208 KB
testcase_05 AC 388 ms
96,204 KB
testcase_06 AC 316 ms
98,612 KB
testcase_07 AC 312 ms
97,360 KB
testcase_08 AC 308 ms
96,972 KB
testcase_09 AC 314 ms
98,260 KB
testcase_10 AC 303 ms
96,628 KB
testcase_11 AC 319 ms
95,928 KB
testcase_12 AC 326 ms
96,152 KB
testcase_13 AC 320 ms
96,236 KB
testcase_14 AC 319 ms
96,828 KB
testcase_15 AC 320 ms
96,136 KB
testcase_16 AC 315 ms
96,776 KB
testcase_17 AC 311 ms
96,300 KB
testcase_18 AC 309 ms
96,080 KB
testcase_19 AC 319 ms
96,632 KB
testcase_20 AC 333 ms
96,912 KB
testcase_21 AC 320 ms
95,768 KB
testcase_22 AC 318 ms
97,300 KB
testcase_23 AC 316 ms
96,604 KB
testcase_24 AC 310 ms
95,968 KB
testcase_25 AC 316 ms
96,244 KB
testcase_26 AC 318 ms
95,812 KB
testcase_27 AC 346 ms
96,200 KB
testcase_28 AC 378 ms
96,140 KB
testcase_29 AC 371 ms
96,580 KB
testcase_30 AC 360 ms
95,720 KB
testcase_31 AC 372 ms
96,572 KB
testcase_32 AC 371 ms
95,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**9)
N=int(input())
E=[]
G=[[] for _ in range(N)]
for _ in range(N-1):
  u,v=map(lambda x:int(x)-1,input().split())
  E.append((u,v))
  G[u].append(v)
  G[v].append(u)
subtree_size=[1]*N
def dfs(G,v,p=-1):
  for nextv in G[v]:
    if nextv!=p:
      dfs(G,nextv,v)
  for c in G[v]:
    if c!=p:
      subtree_size[v]+=subtree_size[c]
dfs(G,0)
p=0
for u,v in E:
  n=min(subtree_size[u],subtree_size[v])
  # print(u,v,n)
  p+=n*(n-1)//2+(N-n)*(N-n-1)//2
q=N*(N-1)//2*(N-1)
while q%998244353==0:
  p//=998244353
  q//=998244353
# print(p,q)
def extgcd(a,b):
  if b:
    d,y,x=extgcd(b,a%b)
    y-=(a//b)*x
    return d,x,y
  return a,1,0
print(p*extgcd(q,998244353)[1]%998244353)
0