結果

問題 No.1507 Road Blocked
ユーザー AEnAEn
提出日時 2022-12-06 21:26:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 629 ms / 2,000 ms
コード長 653 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 10,748 KB
実行使用メモリ 52,248 KB
最終ジャッジ日時 2023-08-03 12:36:36
合計ジャッジ時間 23,236 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,936 KB
testcase_01 AC 17 ms
7,752 KB
testcase_02 AC 17 ms
7,800 KB
testcase_03 AC 496 ms
52,248 KB
testcase_04 AC 613 ms
27,116 KB
testcase_05 AC 613 ms
26,556 KB
testcase_06 AC 612 ms
26,668 KB
testcase_07 AC 608 ms
26,472 KB
testcase_08 AC 614 ms
26,472 KB
testcase_09 AC 607 ms
26,800 KB
testcase_10 AC 607 ms
26,600 KB
testcase_11 AC 621 ms
26,436 KB
testcase_12 AC 621 ms
26,424 KB
testcase_13 AC 614 ms
26,644 KB
testcase_14 AC 612 ms
26,488 KB
testcase_15 AC 624 ms
27,288 KB
testcase_16 AC 626 ms
26,620 KB
testcase_17 AC 622 ms
26,600 KB
testcase_18 AC 612 ms
26,568 KB
testcase_19 AC 609 ms
26,460 KB
testcase_20 AC 608 ms
26,560 KB
testcase_21 AC 618 ms
26,588 KB
testcase_22 AC 629 ms
27,860 KB
testcase_23 AC 625 ms
26,900 KB
testcase_24 AC 614 ms
26,532 KB
testcase_25 AC 620 ms
26,588 KB
testcase_26 AC 618 ms
26,520 KB
testcase_27 AC 622 ms
26,464 KB
testcase_28 AC 623 ms
26,580 KB
testcase_29 AC 627 ms
26,616 KB
testcase_30 AC 621 ms
26,604 KB
testcase_31 AC 610 ms
26,584 KB
testcase_32 AC 620 ms
26,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)

N = int(input())
G = [list() for _ in range(N)]
for i in range(N-1):
    u,v = map(int, input().split())
    u-=1;v-=1
    G[u].append(v)
    G[v].append(u)

depth = [0]*N
sub_tree = [0]*N
num = 0
def dfs(G, v, p, d):
    depth[v] = d
    for next_v in G[v]:
        if next_v == p:
            continue
        dfs(G, next_v, v, d+1)
    sub_tree[v] = 1
    for c in G[v]:
        if c== p:
            continue
        sub_tree[v] += sub_tree[c]
dfs(G,0,-1,0)
for i in range(1,N):
    s = sub_tree[i]
    num += s*(s-1)//2+(N-s)*(N-s-1)//2
mod = 998244353
n = (N-1)*N*(N-1)//2
print((num*pow(n,mod-2,mod))%mod)
0