結果

問題 No.2532 Want Play More
ユーザー hirayuu_ychirayuu_yc
提出日時 2023-06-09 13:29:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 991 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 87,352 KB
実行使用メモリ 379,112 KB
最終ジャッジ日時 2023-10-11 07:58:53
合計ジャッジ時間 14,908 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,392 KB
testcase_01 AC 741 ms
140,784 KB
testcase_02 AC 740 ms
142,528 KB
testcase_03 AC 756 ms
141,364 KB
testcase_04 AC 704 ms
137,816 KB
testcase_05 AC 686 ms
135,056 KB
testcase_06 AC 991 ms
379,112 KB
testcase_07 AC 131 ms
78,848 KB
testcase_08 AC 162 ms
84,300 KB
testcase_09 AC 152 ms
82,636 KB
testcase_10 AC 428 ms
109,372 KB
testcase_11 AC 412 ms
109,716 KB
testcase_12 AC 600 ms
127,056 KB
testcase_13 AC 469 ms
114,300 KB
testcase_14 AC 240 ms
92,316 KB
testcase_15 AC 733 ms
141,776 KB
testcase_16 AC 648 ms
131,696 KB
testcase_17 AC 151 ms
82,452 KB
testcase_18 AC 514 ms
118,768 KB
testcase_19 AC 655 ms
132,868 KB
testcase_20 AC 74 ms
71,444 KB
testcase_21 AC 73 ms
71,420 KB
testcase_22 AC 72 ms
71,296 KB
testcase_23 AC 71 ms
71,400 KB
testcase_24 AC 71 ms
71,296 KB
testcase_25 AC 74 ms
71,120 KB
testcase_26 AC 72 ms
71,304 KB
testcase_27 AC 72 ms
71,480 KB
testcase_28 AC 336 ms
165,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def DFS(now,where):
  if tree[now]=={where} or len(tree[now])==0:
    return 0,0
  else:
    mini=[]
    maxi=[]
    for i in tree[now]:
      if i!=where:
        small,large=DFS(i,now)
        mini.append(small+1)
        maxi.append(large+1)
    return min(maxi),max(mini)

sys.setrecursionlimit(500000)
N=int(input())
tree=[set() for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  tree[a-1].add(b-1)
  tree[b-1].add(a-1)
second,first=DFS(0,-1)
print(first)
print(second)
0