結果
| 問題 |
No.3206 う し た ウ ニ 木 あ く ん 笑
|
| コンテスト | |
| ユーザー |
timi
|
| 提出日時 | 2025-07-18 22:44:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,098 bytes |
| コンパイル時間 | 470 ms |
| コンパイル使用メモリ | 82,564 KB |
| 実行使用メモリ | 148,932 KB |
| 最終ジャッジ日時 | 2025-07-18 22:44:56 |
| 合計ジャッジ時間 | 9,197 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 RE * 24 |
ソースコード
N=int(input())
D=[[] for i in range(N)]
for i in range(N-1):
a,b=map(int, input().split())
a-=1;b-=1
D[a].append(b)
D[b].append(a)
from collections import deque
d=deque()
V=[-1]*N
d.append(0);V[0]=0
while d:
now=d.popleft()
for nex in D[now]:
if V[nex]==-1:
V[nex]=V[now]+1
d.append(nex)
x=V.index(max(V))
V=[-1]*N
d.append(x);V[x]=0
P=[-1]*N
while d:
now=d.popleft()
for nex in D[now]:
if V[nex]==-1:
V[nex]=V[now]+1
d.append(nex)
P[nex]=now
ans=1
y=V.index(max(V))
E=[]
E.append(y)
while True:
if E[-1]==x:
break
E.append(P[E[-1]])
EE=set(E)
for i in range(len(E)):
l,r=i,len(E)-i-1
now=E[i]
d=deque()
F={}
for nex in D[now]:
if nex in EE:
continue
d.append((nex,now,nex,1))
F[nex]=1
while d:
now,p,c,cnt=d.popleft()
for nex in D[now]:
if p==nex:
continue
d.append((nex,now,c,cnt+1))
F[now]=max(F[now],cnt+1)
G=[]
G.append(l)
G.append(r)
for i in F:
G.append(F[i])
G=sorted(G)[::-1]
for i in range(len(G)):
ans=max(ans,1+G[i]*(i+1))
print(ans)
timi