結果
| 問題 | No.2504 NOT Path Painting |
| コンテスト | |
| ユーザー |
sasa8uyauya
|
| 提出日時 | 2025-02-08 14:59:19 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 855 bytes |
| コンパイル時間 | 590 ms |
| コンパイル使用メモリ | 82,840 KB |
| 実行使用メモリ | 110,808 KB |
| 最終ジャッジ日時 | 2025-02-08 14:59:50 |
| 合計ジャッジ時間 | 30,963 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 TLE * 3 |
ソースコード
M=998244353
T=int(input())
for _ in range(T):
n=int(input())
i2=pow(2,M-2,M)
ic=pow(n*(n+1)*i2,M-2,M)
e=[[] for i in range(n)]
for i in range(n-1):
a,b=map(int,input().split())
a-=1
b-=1
e[a]+=[b]
e[b]+=[a]
p1=0
p2=0
v=[0]*n
u=[0]*n
q=[0]
while len(q)>0:
s=q[-1]
if v[s]==0:
v[s]=1
q+=[t for t in e[s] if v[t]==0]
else:
u[s]=1+sum(u[t] for t in e[s] if v[t]==0)
c1=0
c2=0
for t in e[s]:
if v[t]==0:
c1+=u[t]
c2+=u[t]**2
else:
c1+=n-u[s]
c2+=(n-u[s])**2
c1%=M
c2%=M
g1=(c1**2-c2)*i2+n
p1+=pow(1-g1*ic,M-2,M)
p1%=M
for t in e[s]:
if v[t]==0:
g2=u[t]*(n-u[t])
p2+=pow(1-g2*ic,M-2,M)
p2%=M
v[s]=0
q.pop()
print((p1-p2)%M)
sasa8uyauya