結果

問題 No.1507 Road Blocked
ユーザー ああいいああいい
提出日時 2021-12-31 19:18:47
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 500 ms / 2,000 ms
コード長 623 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 10,744 KB
実行使用メモリ 45,088 KB
最終ジャッジ日時 2023-07-30 05:28:37
合計ジャッジ時間 17,542 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,772 KB
testcase_01 AC 16 ms
7,912 KB
testcase_02 AC 17 ms
7,844 KB
testcase_03 AC 391 ms
45,088 KB
testcase_04 AC 481 ms
25,664 KB
testcase_05 AC 485 ms
25,568 KB
testcase_06 AC 494 ms
25,744 KB
testcase_07 AC 489 ms
25,632 KB
testcase_08 AC 499 ms
25,568 KB
testcase_09 AC 487 ms
25,608 KB
testcase_10 AC 494 ms
25,656 KB
testcase_11 AC 496 ms
25,676 KB
testcase_12 AC 485 ms
25,780 KB
testcase_13 AC 482 ms
25,736 KB
testcase_14 AC 485 ms
25,568 KB
testcase_15 AC 475 ms
25,688 KB
testcase_16 AC 495 ms
25,708 KB
testcase_17 AC 494 ms
25,596 KB
testcase_18 AC 496 ms
25,676 KB
testcase_19 AC 492 ms
25,788 KB
testcase_20 AC 493 ms
25,764 KB
testcase_21 AC 489 ms
25,608 KB
testcase_22 AC 486 ms
25,668 KB
testcase_23 AC 482 ms
25,768 KB
testcase_24 AC 499 ms
25,624 KB
testcase_25 AC 478 ms
25,772 KB
testcase_26 AC 500 ms
25,564 KB
testcase_27 AC 478 ms
25,648 KB
testcase_28 AC 490 ms
25,728 KB
testcase_29 AC 476 ms
25,588 KB
testcase_30 AC 483 ms
25,648 KB
testcase_31 AC 482 ms
25,660 KB
testcase_32 AC 474 ms
25,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 6)

N = int(input())
P = 998244353

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

memo = [0] * (N + 1)
ans = 0
def dfs(now = 1,parent = 0):
    global ans
    if now != 1 and len(G[now]) == 1:
        ans = (ans + N - 1) % P
        return 1
    count = 1
    for v in G[now]:
        if v != parent:
            count += dfs(v,now)
    ans = (ans + count * (N - count)) % P
    return count
dfs()
inv = pow(N * (N - 1) * (N - 1) // 2,P - 2,P)
ans = N * (N - 1) * (N - 1) // 2 - ans
print(ans * inv % P)
0