結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー |
![]() |
提出日時 | 2025-02-11 08:56:24 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 796 ms / 2,000 ms |
コード長 | 929 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 12,160 KB |
実行使用メモリ | 47,104 KB |
最終ジャッジ日時 | 2025-03-22 10:44:24 |
合計ジャッジ時間 | 13,586 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
n=int(input())E=[[] for i in range(n)]for i in range(n-1):x,y=map(int,input().split())x-=1y-=1E[x].append(y)E[y].append(x)# 木のHL分解+LCAROOT=0QUE=[ROOT]Parent=[-1]*nParent[ROOT]=n # ROOTの親を定めておく.Child=[[] for i in range(n)]TOP_SORT=[] # トポロジカルソートwhile QUE: # トポロジカルソートと同時に親を見つけるx=QUE.pop()TOP_SORT.append(x)for to in E[x]:if Parent[to]==-1:Parent[to]=xChild[x].append(to)QUE.append(to)DP=[0]*nDP2=[0]*nfor x in TOP_SORT[::-1]:if Child[x]==[]:DP[x]=1DP2[x]=0else:score=0for c in Child[x]:score+=max(DP2[c],DP[c])DP2[x]=scorescore=0for c in Child[x]:score+=max(DP2[c],DP[c]-1)DP[x]=score+1print(max(DP[0],DP2[0]))