結果
問題 | No.2677 Minmax Independent Set |
ユーザー | nikoro256 |
提出日時 | 2024-03-19 22:30:32 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 811 ms / 2,000 ms |
コード長 | 1,384 bytes |
コンパイル時間 | 144 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 136,980 KB |
最終ジャッジ日時 | 2024-09-30 05:50:08 |
合計ジャッジ時間 | 26,754 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
53,888 KB |
testcase_01 | AC | 44 ms
54,528 KB |
testcase_02 | AC | 41 ms
53,888 KB |
testcase_03 | AC | 38 ms
54,144 KB |
testcase_04 | AC | 40 ms
53,888 KB |
testcase_05 | AC | 679 ms
127,488 KB |
testcase_06 | AC | 700 ms
127,604 KB |
testcase_07 | AC | 677 ms
127,476 KB |
testcase_08 | AC | 676 ms
127,476 KB |
testcase_09 | AC | 656 ms
127,612 KB |
testcase_10 | AC | 687 ms
134,488 KB |
testcase_11 | AC | 643 ms
134,496 KB |
testcase_12 | AC | 553 ms
128,880 KB |
testcase_13 | AC | 748 ms
132,692 KB |
testcase_14 | AC | 713 ms
136,464 KB |
testcase_15 | AC | 728 ms
134,304 KB |
testcase_16 | AC | 809 ms
127,888 KB |
testcase_17 | AC | 811 ms
127,688 KB |
testcase_18 | AC | 495 ms
109,580 KB |
testcase_19 | AC | 602 ms
115,652 KB |
testcase_20 | AC | 252 ms
91,556 KB |
testcase_21 | AC | 668 ms
119,588 KB |
testcase_22 | AC | 127 ms
80,896 KB |
testcase_23 | AC | 54 ms
67,584 KB |
testcase_24 | AC | 50 ms
61,184 KB |
testcase_25 | AC | 46 ms
59,648 KB |
testcase_26 | AC | 45 ms
61,824 KB |
testcase_27 | AC | 52 ms
65,920 KB |
testcase_28 | AC | 610 ms
136,980 KB |
testcase_29 | AC | 688 ms
129,300 KB |
testcase_30 | AC | 40 ms
53,888 KB |
testcase_31 | AC | 40 ms
53,888 KB |
testcase_32 | AC | 40 ms
53,760 KB |
testcase_33 | AC | 38 ms
54,656 KB |
testcase_34 | AC | 40 ms
54,144 KB |
testcase_35 | AC | 44 ms
60,160 KB |
testcase_36 | AC | 45 ms
61,184 KB |
testcase_37 | AC | 50 ms
64,256 KB |
testcase_38 | AC | 55 ms
68,736 KB |
testcase_39 | AC | 94 ms
78,080 KB |
testcase_40 | AC | 99 ms
78,408 KB |
testcase_41 | AC | 102 ms
79,232 KB |
testcase_42 | AC | 114 ms
80,348 KB |
testcase_43 | AC | 164 ms
84,480 KB |
testcase_44 | AC | 228 ms
90,496 KB |
testcase_45 | AC | 400 ms
102,924 KB |
testcase_46 | AC | 768 ms
127,144 KB |
testcase_47 | AC | 791 ms
128,228 KB |
testcase_48 | AC | 797 ms
128,112 KB |
testcase_49 | AC | 800 ms
127,904 KB |
testcase_50 | AC | 261 ms
98,324 KB |
testcase_51 | AC | 89 ms
78,592 KB |
testcase_52 | AC | 514 ms
125,976 KB |
testcase_53 | AC | 466 ms
121,024 KB |
testcase_54 | AC | 97 ms
78,208 KB |
testcase_55 | AC | 675 ms
135,860 KB |
testcase_56 | AC | 651 ms
134,888 KB |
testcase_57 | AC | 639 ms
134,908 KB |
testcase_58 | AC | 660 ms
135,980 KB |
testcase_59 | AC | 672 ms
134,920 KB |
testcase_60 | AC | 407 ms
129,588 KB |
testcase_61 | AC | 404 ms
126,716 KB |
testcase_62 | AC | 397 ms
127,832 KB |
testcase_63 | AC | 427 ms
129,580 KB |
ソースコード
# 全方位木DP # https://qiita.com/Kiri8128/items/a011c90d25911bdb3ed3#bottom-up-%E9%83%A8%E5%88%86 import sys input = sys.stdin.readline from collections import deque N=int(input()) mod=998244353 X = [[] for i in range(N)] for i in range(N-1): x, y = map(int, input().split()) X[x-1].append(y-1) X[y-1].append(x-1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) ##### Settings unit = (0,0) merge = lambda a, b: (max(a)+max(b),a[1]+b[1]) adj_bu = lambda a, i: (a[1]+1,a[0]) adj_td = lambda a, i, p: (a[1]+1,a[0]) adj_fin = lambda a, i: (a[1]+1,a[0]) ##### ME = [unit] * N XX = [0] * N TD = [unit] * N for i in R[1:][::-1]: XX[i] = adj_bu(ME[i], i) p = P[i] ME[p] = merge(ME[p], XX[i]) XX[R[0]] = adj_fin(ME[R[0]], R[0]) # print("ME =", ME) # Merge before adj # print("XX =", XX) # Bottom-up after adj for i in R: ac = TD[i] for j in X[i]: TD[j] = ac ac = merge(ac, XX[j]) ac = unit for j in X[i][::-1]: TD[j] = adj_td(merge(TD[j], ac), j, i) ac = merge(ac, XX[j]) XX[j] = adj_fin(merge(ME[j], TD[j]), j) # print("TD =", TD) # Top-down after adj # print("XX =", XX) # Final Result #print(*XX, sep = "\n") print(min([x[0] for x in XX]))