結果
| 問題 |
No.1507 Road Blocked
|
| コンテスト | |
| ユーザー |
sasa8uyauya
|
| 提出日時 | 2024-11-08 00:12:57 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 398 ms / 2,000 ms |
| コード長 | 444 bytes |
| コンパイル時間 | 177 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 93,004 KB |
| 最終ジャッジ日時 | 2024-11-08 00:13:11 |
| 合計ジャッジ時間 | 12,896 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
n=int(input())
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]
M=998244353
p=0
v=[0]*n
c=[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:
c[s]+=1
c[s]+=sum(c[t]*(v[t]==0) for t in e[s])
if s!=0:
p+=c[s]*(c[s]-1)+(n-c[s])*(n-c[s]-1)
p%=M
v[s]=0
q.pop()
print(p*pow(n*(n-1)*(n-1),M-2,M)%M)
sasa8uyauya