結果

問題 No.2532 Want Play More
ユーザー sasa8uyauyasasa8uyauya
提出日時 2023-11-03 22:35:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 617 ms / 2,000 ms
コード長 1,121 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 131,300 KB
最終ジャッジ日時 2023-11-03 22:36:06
合計ジャッジ時間 9,321 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,472 KB
testcase_01 AC 617 ms
113,468 KB
testcase_02 AC 607 ms
112,868 KB
testcase_03 AC 558 ms
111,948 KB
testcase_04 AC 528 ms
111,348 KB
testcase_05 AC 528 ms
110,304 KB
testcase_06 AC 276 ms
131,300 KB
testcase_07 AC 119 ms
77,584 KB
testcase_08 AC 125 ms
78,084 KB
testcase_09 AC 137 ms
78,376 KB
testcase_10 AC 315 ms
93,980 KB
testcase_11 AC 304 ms
93,024 KB
testcase_12 AC 440 ms
104,032 KB
testcase_13 AC 338 ms
96,584 KB
testcase_14 AC 195 ms
83,848 KB
testcase_15 AC 561 ms
112,584 KB
testcase_16 AC 503 ms
107,068 KB
testcase_17 AC 147 ms
78,416 KB
testcase_18 AC 381 ms
100,276 KB
testcase_19 AC 557 ms
108,516 KB
testcase_20 AC 33 ms
53,472 KB
testcase_21 AC 37 ms
53,472 KB
testcase_22 AC 32 ms
53,472 KB
testcase_23 AC 31 ms
53,472 KB
testcase_24 AC 31 ms
53,472 KB
testcase_25 AC 32 ms
53,472 KB
testcase_26 AC 31 ms
53,472 KB
testcase_27 AC 31 ms
53,472 KB
testcase_28 AC 228 ms
112,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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]

v=[-1]*n
v[0]=0
q=[0]
f=[0]*n
g=[0]*n
p=[0]*n
while len(q)>0:
  s=q[-1]
  while g[s]<len(e[s]):
    t=e[s][g[s]]
    if v[t]==-1:
      f[s]=1
      break
    g[s]+=1
  if g[s]<len(e[s]):
    v[t]=1-v[s]
    q+=[t]
  else:
    if f[s] and v[s]==0:
      d=0
      for t in e[s]:
        if s==0 or t!=q[-2]:
          d=max(d,p[t])
      p[s]=d+1
    if f[s] and v[s]==1:
      d=n
      for t in e[s]:
        if s==0 or t!=q[-2]:
          d=min(d,p[t])
      p[s]=d+1
    q.pop()
print(p[0])

v=[-1]*n
v[0]=1
q=[0]
f=[0]*n
g=[0]*n
p=[0]*n
while len(q)>0:
  s=q[-1]
  while g[s]<len(e[s]):
    t=e[s][g[s]]
    if v[t]==-1:
      f[s]=1
      break
    g[s]+=1
  if g[s]<len(e[s]):
    v[t]=1-v[s]
    q+=[t]
  else:
    if f[s] and v[s]==0:
      d=0
      for t in e[s]:
        if s==0 or t!=q[-2]:
          d=max(d,p[t])
      p[s]=d+1
    if f[s] and v[s]==1:
      d=n
      for t in e[s]:
        if s==0 or t!=q[-2]:
          d=min(d,p[t])
      p[s]=d+1
    q.pop()
print(p[0])
0