結果
問題 | No.1928 Make a Binary Tree |
ユーザー | ikoma |
提出日時 | 2022-05-06 22:50:53 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,247 bytes |
コンパイル時間 | 304 ms |
コンパイル使用メモリ | 87,172 KB |
実行使用メモリ | 518,028 KB |
最終ジャッジ日時 | 2023-09-20 03:59:21 |
合計ジャッジ時間 | 13,429 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 79 ms
71,608 KB |
testcase_01 | AC | 77 ms
71,380 KB |
testcase_02 | AC | 76 ms
71,220 KB |
testcase_03 | AC | 76 ms
71,424 KB |
testcase_04 | AC | 74 ms
71,536 KB |
testcase_05 | AC | 76 ms
71,388 KB |
testcase_06 | WA | - |
testcase_07 | AC | 77 ms
71,692 KB |
testcase_08 | AC | 76 ms
71,516 KB |
testcase_09 | AC | 76 ms
71,580 KB |
testcase_10 | AC | 78 ms
71,376 KB |
testcase_11 | AC | 76 ms
71,460 KB |
testcase_12 | AC | 77 ms
71,416 KB |
testcase_13 | WA | - |
testcase_14 | AC | 75 ms
71,708 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 312 ms
130,972 KB |
testcase_36 | MLE | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
ソースコード
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) if "pypyjit" in sys.builtin_module_names: import pypyjit pypyjit.set_param("max_unroll_recursion=-1") N=int(input()) edge = [[] for _ in range(N)] XY=[list(map(int,input().split())) for _ in range(N-1)] for x,y in XY: x,y=x-1,y-1 edge[x].append(y) edge[y].append(x) visit = [0]*N dnode = [] from heapq import * def dfs(v=0): visit[v]=1 n_tree = [] del_lst = [] for to in edge[v]: if visit[to]:continue n,lst = dfs(to) n_tree.append(n) del_lst.extend(lst) if len(n_tree)==0: return 1,[] if len(n_tree)==1: if del_lst: # heapify(del_lst) n = -heappop(del_lst) else: n=0 return n+n_tree[0]+1,del_lst if len(n_tree)<=2: return sum(n_tree)+1,del_lst # n_tree.sort(reverse=True) # 重い mx1,mx2=0,0 for n in n_tree: if mx1<n: mx2=mx1 mx1=n elif mx2<n: mx2=n ret = mx1+mx2+1 for i in n_tree: if i!=mx1: if i!=mx2: heappush(del_lst, -i) else:mx2=-1 else:mx1=-1 return ret,del_lst ans,dl = dfs() print(ans)