結果
| 問題 | 
                            No.1507 Road Blocked
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-01-15 19:42:37 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 895 bytes | 
| コンパイル時間 | 364 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 29,568 KB | 
| 最終ジャッジ日時 | 2024-12-29 10:52:37 | 
| 合計ジャッジ時間 | 18,770 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 29 RE * 1 | 
ソースコード
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)