結果
問題 | No.2584 The University of Tree |
ユーザー | hirayuu_yc |
提出日時 | 2023-11-27 21:40:31 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,868 bytes |
コンパイル時間 | 410 ms |
コンパイル使用メモリ | 12,032 KB |
実行使用メモリ | 106,804 KB |
最終ジャッジ日時 | 2023-12-11 23:30:30 |
合計ジャッジ時間 | 26,287 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
10,368 KB |
testcase_01 | AC | 28 ms
10,368 KB |
testcase_02 | AC | 27 ms
10,368 KB |
testcase_03 | AC | 27 ms
10,368 KB |
testcase_04 | AC | 31 ms
10,368 KB |
testcase_05 | AC | 31 ms
10,368 KB |
testcase_06 | AC | 32 ms
10,368 KB |
testcase_07 | AC | 31 ms
10,368 KB |
testcase_08 | AC | 31 ms
10,368 KB |
testcase_09 | AC | 32 ms
10,368 KB |
testcase_10 | AC | 32 ms
10,368 KB |
testcase_11 | AC | 33 ms
10,368 KB |
testcase_12 | AC | 33 ms
10,368 KB |
testcase_13 | AC | 33 ms
10,368 KB |
testcase_14 | AC | 33 ms
10,368 KB |
testcase_15 | AC | 33 ms
10,368 KB |
testcase_16 | AC | 32 ms
10,368 KB |
testcase_17 | AC | 32 ms
10,368 KB |
testcase_18 | AC | 34 ms
10,368 KB |
testcase_19 | AC | 33 ms
10,368 KB |
testcase_20 | AC | 33 ms
10,368 KB |
testcase_21 | AC | 32 ms
10,368 KB |
testcase_22 | AC | 2,546 ms
79,104 KB |
testcase_23 | AC | 2,957 ms
106,804 KB |
testcase_24 | AC | 1,788 ms
57,472 KB |
testcase_25 | AC | 2,072 ms
65,024 KB |
testcase_26 | AC | 1,318 ms
52,332 KB |
testcase_27 | AC | 2,493 ms
82,472 KB |
testcase_28 | AC | 1,299 ms
47,972 KB |
testcase_29 | AC | 732 ms
30,848 KB |
testcase_30 | TLE | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
ソースコード
from collections import deque MOD=998244353 N=int(input()) gr=[] road=[[] for i in range(N-1)] for i in range(N): C,*E=list(map(int,input().split())) gr.append(E) for j in E: road[j-1].append(i) ser=[{} for i in range(N)] for i in range(N): for j,k in enumerate(gr[i]): if road[k-1][0]==i: gr[i][j]=road[k-1][1] else: gr[i][j]=road[k-1][0] ser[i][gr[i][j]]=j dp=[[-1]*len(gr[i]) for i in range(N)] top=[] vert=deque([(0,0,-1)]) while len(vert)>0: st,pos,bef=vert.pop() if st==0: top.append(pos) vert.append((1,pos,bef)) for i in gr[pos]: if i!=bef: vert.append((0,i,pos)) else: if bef==-1: continue prod=pos+1 ret=0 for i in range(ser[pos][bef]+1,len(gr[pos])): ret+=dp[pos][ser[pos][gr[pos][i]]]*prod prod*=pos+1 ret%=MOD prod%=MOD ret+=prod prod*=pos+1 for i in range(ser[pos][bef]): ret+=dp[pos][ser[pos][gr[pos][i]]]*prod prod*=pos+1 ret%=MOD prod%=MOD dp[bef][ser[bef][pos]]=ret for i in top: lf=[0] ri=[0] rev=pow(i+1,-1,MOD) prod=i+1 for j in dp[i]: lf.append(lf[-1]+j*prod) prod*=i+1 prod%=MOD lf[-1]%=MOD prod=rev for j in reversed(dp[i]): ri.append(ri[-1]+j*prod) prod*=rev prod%=MOD ri[-1]%=MOD cul=-2 cur=0 prod=i+1 for j in reversed(gr[i]): dp[j][ser[j][i]]=prod+(lf[cul]+ri[cur])*prod dp[j][ser[j][i]]%=MOD prod*=i+1 prod%=MOD cur+=1 cul-=1 for i in range(N): ans=0 prod=i+1 for j in dp[i]: ans+=j*prod ans%=MOD prod*=i+1 prod%=MOD print(ans)