結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー |
|
提出日時 | 2024-10-14 21:06:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 345 ms / 2,000 ms |
コード長 | 817 bytes |
コンパイル時間 | 360 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 178,196 KB |
最終ジャッジ日時 | 2024-10-14 21:07:03 |
合計ジャッジ時間 | 8,069 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
import syssys.setrecursionlimit(100000+10)from collections import dequeN = int(input())G = {i:[] for i in range(1,N+1)}for _ in range(N-1):u,v = map(int,input().split())G[u].append(v)G[v].append(u)deg = [0]*(N+1)P = [0]*(N+1)def dfs(x,p):for y in G[x]:if y==p:continuedeg[x] += 1P[y] = xdfs(y,x)dfs(1,0)dp = [0]*(N+1)deg1 = deg[:]que = deque([])for i in range(1,N+1):if deg[i]==0:que.append(i)F = [0]*(N+1)while que:x = que.popleft()if deg[x]==0:dp[x] = 1else:dp[x] = F[x]cnt = 1for y in G[x]:if y==P[x]:continuecnt += F[y]dp[x] = max(dp[x],cnt)F[P[x]] += dp[x]deg1[P[x]] -= 1if deg1[P[x]]==0:que.append(P[x])print(dp[1])