結果
問題 | No.1928 Make a Binary Tree |
ユーザー | mkawa2 |
提出日時 | 2022-05-08 10:44:17 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 913 ms / 3,000 ms |
コード長 | 1,347 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 98,816 KB |
最終ジャッジ日時 | 2024-07-07 21:33:51 |
合計ジャッジ時間 | 28,976 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
10,752 KB |
testcase_01 | AC | 25 ms
10,880 KB |
testcase_02 | AC | 27 ms
10,752 KB |
testcase_03 | AC | 28 ms
10,752 KB |
testcase_04 | AC | 27 ms
10,880 KB |
testcase_05 | AC | 25 ms
10,752 KB |
testcase_06 | AC | 25 ms
10,752 KB |
testcase_07 | AC | 24 ms
10,752 KB |
testcase_08 | AC | 25 ms
10,880 KB |
testcase_09 | AC | 25 ms
10,880 KB |
testcase_10 | AC | 25 ms
10,752 KB |
testcase_11 | AC | 25 ms
10,880 KB |
testcase_12 | AC | 27 ms
10,752 KB |
testcase_13 | AC | 25 ms
10,880 KB |
testcase_14 | AC | 24 ms
10,752 KB |
testcase_15 | AC | 54 ms
13,184 KB |
testcase_16 | AC | 47 ms
12,544 KB |
testcase_17 | AC | 39 ms
12,032 KB |
testcase_18 | AC | 52 ms
13,056 KB |
testcase_19 | AC | 29 ms
11,136 KB |
testcase_20 | AC | 42 ms
12,160 KB |
testcase_21 | AC | 34 ms
11,520 KB |
testcase_22 | AC | 45 ms
12,416 KB |
testcase_23 | AC | 38 ms
11,904 KB |
testcase_24 | AC | 49 ms
12,928 KB |
testcase_25 | AC | 55 ms
13,440 KB |
testcase_26 | AC | 757 ms
55,552 KB |
testcase_27 | AC | 400 ms
38,656 KB |
testcase_28 | AC | 454 ms
41,216 KB |
testcase_29 | AC | 901 ms
61,952 KB |
testcase_30 | AC | 380 ms
36,608 KB |
testcase_31 | AC | 524 ms
45,056 KB |
testcase_32 | AC | 913 ms
60,288 KB |
testcase_33 | AC | 444 ms
39,296 KB |
testcase_34 | AC | 528 ms
45,568 KB |
testcase_35 | AC | 656 ms
65,404 KB |
testcase_36 | AC | 739 ms
80,640 KB |
testcase_37 | AC | 663 ms
64,128 KB |
testcase_38 | AC | 26 ms
10,752 KB |
testcase_39 | AC | 793 ms
80,512 KB |
testcase_40 | AC | 806 ms
80,384 KB |
testcase_41 | AC | 801 ms
80,256 KB |
testcase_42 | AC | 804 ms
80,384 KB |
testcase_43 | AC | 802 ms
80,256 KB |
testcase_44 | AC | 808 ms
80,256 KB |
testcase_45 | AC | 819 ms
80,384 KB |
testcase_46 | AC | 811 ms
80,512 KB |
testcase_47 | AC | 808 ms
80,384 KB |
testcase_48 | AC | 803 ms
80,256 KB |
testcase_49 | AC | 731 ms
98,816 KB |
testcase_50 | AC | 883 ms
59,520 KB |
testcase_51 | AC | 870 ms
59,648 KB |
testcase_52 | AC | 860 ms
59,648 KB |
testcase_53 | AC | 873 ms
59,648 KB |
testcase_54 | AC | 875 ms
59,520 KB |
testcase_55 | AC | 709 ms
82,304 KB |
testcase_56 | AC | 908 ms
62,208 KB |
testcase_57 | AC | 907 ms
62,080 KB |
testcase_58 | AC | 905 ms
62,592 KB |
testcase_59 | AC | 735 ms
56,448 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) heappush(hps[u], -size[v]) if hps[u]: size[u] -= heappop(hps[u]) if hps[u]: size[u] -= heappop(hps[u]) dfs() print(size[0])