結果
問題 | No.1928 Make a Binary Tree |
ユーザー | mkawa2 |
提出日時 | 2022-05-06 22:06:44 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,460 bytes |
コンパイル時間 | 86 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 116,224 KB |
最終ジャッジ日時 | 2024-07-05 23:22:07 |
合計ジャッジ時間 | 39,816 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
11,136 KB |
testcase_01 | AC | 32 ms
11,008 KB |
testcase_02 | AC | 34 ms
10,880 KB |
testcase_03 | AC | 35 ms
11,008 KB |
testcase_04 | AC | 31 ms
11,008 KB |
testcase_05 | AC | 31 ms
11,008 KB |
testcase_06 | WA | - |
testcase_07 | AC | 32 ms
10,880 KB |
testcase_08 | AC | 32 ms
10,880 KB |
testcase_09 | AC | 31 ms
10,880 KB |
testcase_10 | AC | 31 ms
10,880 KB |
testcase_11 | AC | 31 ms
11,008 KB |
testcase_12 | AC | 31 ms
11,008 KB |
testcase_13 | WA | - |
testcase_14 | AC | 31 ms
10,880 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 | 942 ms
65,528 KB |
testcase_36 | AC | 1,020 ms
91,008 KB |
testcase_37 | AC | 906 ms
63,104 KB |
testcase_38 | AC | 32 ms
11,008 KB |
testcase_39 | AC | 1,217 ms
88,960 KB |
testcase_40 | AC | 1,240 ms
89,088 KB |
testcase_41 | AC | 1,233 ms
88,960 KB |
testcase_42 | AC | 1,223 ms
89,088 KB |
testcase_43 | AC | 1,216 ms
88,960 KB |
testcase_44 | AC | 1,231 ms
88,960 KB |
testcase_45 | AC | 1,219 ms
89,088 KB |
testcase_46 | AC | 1,217 ms
88,960 KB |
testcase_47 | AC | 1,252 ms
89,088 KB |
testcase_48 | AC | 1,202 ms
89,088 KB |
testcase_49 | AC | 1,053 ms
116,224 KB |
testcase_50 | AC | 1,251 ms
59,520 KB |
testcase_51 | AC | 1,245 ms
59,648 KB |
testcase_52 | AC | 1,245 ms
59,520 KB |
testcase_53 | AC | 1,256 ms
59,648 KB |
testcase_54 | AC | 1,244 ms
59,648 KB |
testcase_55 | AC | 1,009 ms
91,136 KB |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | AC | 1,069 ms
59,520 KB |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 # md = 10**9+7 md = 998244353 from heapq import * n = II() to = [[] for _ in range(n)] for _ in range(n-1): u, v = LI1() to[u].append(v) to[v].append(u) size = [1]*n hps = [[] for _ in range(n)] def merge(u, v): swap = False if len(hps[u]) < len(hps[v]): u, v = v, u swap = True for s in hps[v]: heappush(hps[u], s) if swap: hps[v] = hps[u] def dfs(u=0, par=-1): ss = [] for v in to[u]: if v == par: continue dfs(v, u) merge(u, v) ss.append(size[v]) ss.sort(reverse=True) size[u] += sum(ss[:2]) for s in ss[2:]: heappush(hps[u], -s) if len(ss) < 2 and hps[u]: s = -heappop(hps[u]) size[u] += s # print(u, par, size, hps) dfs() print(size[0])