結果

問題 No.1507 Road Blocked
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-01-15 19:42:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 895 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 27,304 KB
最終ジャッジ日時 2023-08-28 12:13:32
合計ジャッジ時間 17,430 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,740 KB
testcase_01 AC 21 ms
8,776 KB
testcase_02 AC 21 ms
8,928 KB
testcase_03 RE -
testcase_04 AC 435 ms
27,064 KB
testcase_05 AC 438 ms
27,268 KB
testcase_06 AC 436 ms
27,164 KB
testcase_07 AC 437 ms
27,180 KB
testcase_08 AC 432 ms
27,080 KB
testcase_09 AC 433 ms
27,180 KB
testcase_10 AC 427 ms
27,140 KB
testcase_11 AC 423 ms
27,068 KB
testcase_12 AC 420 ms
27,132 KB
testcase_13 AC 420 ms
27,144 KB
testcase_14 AC 421 ms
27,140 KB
testcase_15 AC 422 ms
27,304 KB
testcase_16 AC 426 ms
27,236 KB
testcase_17 AC 426 ms
27,140 KB
testcase_18 AC 420 ms
27,140 KB
testcase_19 AC 426 ms
27,172 KB
testcase_20 AC 428 ms
27,096 KB
testcase_21 AC 426 ms
27,176 KB
testcase_22 AC 430 ms
27,068 KB
testcase_23 AC 424 ms
27,200 KB
testcase_24 AC 417 ms
27,172 KB
testcase_25 AC 429 ms
27,220 KB
testcase_26 AC 448 ms
27,172 KB
testcase_27 AC 428 ms
27,056 KB
testcase_28 AC 456 ms
27,172 KB
testcase_29 AC 450 ms
27,168 KB
testcase_30 AC 440 ms
27,244 KB
testcase_31 AC 438 ms
27,212 KB
testcase_32 AC 416 ms
27,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from heapq import *
from functools import *
import sys,math
input = sys.stdin.readline

N = int(input())
e = [[] for _ in range(N)]
for _ in range(N-1):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    e[u].append(v)
    e[v].append(u)
mod = 998244353
parents = [-1]*N
sub = [-1]*N
def dfs(x):
    tmp = 1
    if len(e[x]) == 1 and x != 0:
        sub[x] = 1
        return 1
    for ix in e[x]:
        if ix == parents[x]:
            continue
        parents[ix] = x
        if sub[ix] != -1:
            tmp += sub[ix]
        else:
            tmp += dfs(ix)
    sub[x] = tmp
    return tmp
dfs(0)

ans = 0
N_inv = pow(N-1,mod-2,mod)
M_inv = pow(N*(N-1)//2%mod,mod-2,mod)
for i in range(1,N):
    
    ans += ((N-sub[i])*(N-sub[i]-1)//2%mod+(sub[i]*(sub[i]-1)//2)%mod)*M_inv%mod
    ans %= mod
ans *= N_inv
ans %= mod
print(ans)
0