結果

問題 No.2677 Minmax Independent Set
ユーザー suisensuisen
提出日時 2024-03-15 22:12:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 844 ms / 2,000 ms
コード長 568 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 128,840 KB
最終ジャッジ日時 2024-03-15 22:12:45
合計ジャッジ時間 24,321 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 606 ms
113,492 KB
testcase_06 AC 574 ms
113,392 KB
testcase_07 AC 595 ms
114,004 KB
testcase_08 AC 555 ms
113,388 KB
testcase_09 AC 583 ms
114,016 KB
testcase_10 AC 548 ms
118,548 KB
testcase_11 AC 567 ms
118,444 KB
testcase_12 AC 575 ms
128,840 KB
testcase_13 AC 662 ms
122,972 KB
testcase_14 AC 623 ms
120,872 KB
testcase_15 AC 738 ms
123,868 KB
testcase_16 AC 844 ms
115,424 KB
testcase_17 AC 818 ms
115,512 KB
testcase_18 AC 528 ms
106,060 KB
testcase_19 AC 626 ms
112,476 KB
testcase_20 AC 235 ms
86,320 KB
testcase_21 AC 673 ms
109,916 KB
testcase_22 AC 148 ms
79,248 KB
testcase_23 AC 60 ms
66,352 KB
testcase_24 AC 41 ms
53,460 KB
testcase_25 AC 38 ms
53,460 KB
testcase_26 AC 40 ms
53,460 KB
testcase_27 AC 54 ms
64,292 KB
testcase_28 AC 441 ms
124,372 KB
testcase_29 AC 615 ms
121,820 KB
testcase_30 AC 37 ms
53,460 KB
testcase_31 AC 39 ms
53,460 KB
testcase_32 AC 37 ms
53,460 KB
testcase_33 AC 37 ms
53,460 KB
testcase_34 AC 38 ms
53,460 KB
testcase_35 AC 41 ms
53,460 KB
testcase_36 AC 41 ms
53,460 KB
testcase_37 AC 45 ms
55,588 KB
testcase_38 AC 61 ms
65,816 KB
testcase_39 AC 95 ms
76,572 KB
testcase_40 AC 120 ms
77,200 KB
testcase_41 AC 118 ms
77,456 KB
testcase_42 AC 126 ms
77,840 KB
testcase_43 AC 155 ms
80,564 KB
testcase_44 AC 234 ms
86,388 KB
testcase_45 AC 365 ms
99,064 KB
testcase_46 AC 704 ms
115,532 KB
testcase_47 AC 725 ms
120,548 KB
testcase_48 AC 703 ms
119,940 KB
testcase_49 AC 725 ms
119,932 KB
testcase_50 AC 203 ms
91,192 KB
testcase_51 AC 94 ms
76,932 KB
testcase_52 AC 417 ms
115,768 KB
testcase_53 AC 384 ms
104,920 KB
testcase_54 AC 96 ms
76,804 KB
testcase_55 AC 551 ms
118,428 KB
testcase_56 AC 503 ms
114,816 KB
testcase_57 AC 592 ms
118,032 KB
testcase_58 AC 555 ms
118,604 KB
testcase_59 AC 624 ms
117,968 KB
testcase_60 AC 336 ms
118,420 KB
testcase_61 AC 297 ms
115,016 KB
testcase_62 AC 339 ms
113,228 KB
testcase_63 AC 284 ms
115,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
g=[[]for _ in range(n)]
for _ in range(n-1):
 u,v=map(int,input().split());u-=1;v-=1
 g[u]+=[v];g[v]+=[u]
p=[-1]*n
q=[0]
for u in q:
 for v in g[u]:
  if p[u]==v:continue
  p[v]=u;q+=[v]
dp=[(0,0)for _ in range(n)]
for u in q[::-1]:
 u0,u1=0,1
 for v in g[u]:
  if v==p[u]:continue
  v0,v1=dp[v]
  u0+=max(v0,v1)
  u1+=v0
 dp[u]=u0,u1
dp2=dp[:]
for u in q:
 u0,u1=dp2[u]
 for v in g[u]:
  if p[u]==v:continue
  v0,v1=dp[v]
  u0_v=u0-max(v0,v1)
  u1_v=u1-v0
  dp2[v]=(v0+max(u0_v,u1_v),v1+u0_v)
ans=n
for u in range(n):
 ans=min(ans,dp2[u][1])
print(ans)
0