結果

問題 No.1582 Vertexes vs Edges
ユーザー yuusanlondonyuusanlondon
提出日時 2021-07-02 22:32:14
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 987 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 109,448 KB
最終ジャッジ日時 2023-09-11 22:49:50
合計ジャッジ時間 9,441 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,204 KB
testcase_01 AC 71 ms
71,540 KB
testcase_02 AC 70 ms
71,380 KB
testcase_03 AC 72 ms
71,236 KB
testcase_04 AC 138 ms
78,488 KB
testcase_05 AC 219 ms
99,604 KB
testcase_06 AC 129 ms
78,968 KB
testcase_07 AC 134 ms
78,944 KB
testcase_08 AC 179 ms
90,228 KB
testcase_09 AC 215 ms
100,640 KB
testcase_10 AC 195 ms
91,380 KB
testcase_11 AC 128 ms
78,592 KB
testcase_12 AC 163 ms
86,372 KB
testcase_13 AC 208 ms
92,088 KB
testcase_14 AC 215 ms
93,060 KB
testcase_15 AC 265 ms
101,860 KB
testcase_16 AC 182 ms
86,480 KB
testcase_17 AC 208 ms
93,504 KB
testcase_18 AC 265 ms
106,556 KB
testcase_19 AC 192 ms
91,888 KB
testcase_20 AC 204 ms
92,536 KB
testcase_21 AC 184 ms
91,152 KB
testcase_22 AC 237 ms
100,184 KB
testcase_23 AC 167 ms
84,396 KB
testcase_24 AC 146 ms
81,300 KB
testcase_25 AC 191 ms
90,484 KB
testcase_26 AC 182 ms
85,672 KB
testcase_27 AC 258 ms
101,192 KB
testcase_28 AC 158 ms
83,948 KB
testcase_29 AC 234 ms
92,728 KB
testcase_30 AC 171 ms
87,196 KB
testcase_31 AC 228 ms
94,684 KB
testcase_32 AC 162 ms
85,104 KB
testcase_33 AC 307 ms
109,004 KB
testcase_34 AC 304 ms
109,184 KB
testcase_35 AC 320 ms
109,448 KB
testcase_36 AC 69 ms
71,384 KB
testcase_37 AC 70 ms
71,468 KB
testcase_38 AC 69 ms
71,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
graph=[]
for i in range(n):
  graph.append([])
for i in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
childcount=[0]*n
children=[]
for i in range(n):
  children.append([])
whitedp=[0]*n
blackdp=[0]*n
visited=[0]*n
parent=[0]*n
stack=[0]
while stack:
  v=stack.pop()
  visited[v]=1
  for i in graph[v]:
    if not visited[i]:
      stack.append(i)
      children[v].append(i)
      parent[i]=v
stack=[]
for i in range(n):
  childcount[i]=len(children[i])
  if childcount[i]==0:
    stack.append(i)
    whitedp[i]=1
donechildcount=[0]*n
while stack:
  v=stack.pop()
  par=parent[v]
  donechildcount[parent[v]]+=1
  if donechildcount[parent[v]]==childcount[parent[v]]:
    stack.append(par)
    count=0
    for chi in children[par]:
      count+=blackdp[chi]
    whitedp[par]=count+1
    count=0
    for chi in children[par]:
      count+=max(whitedp[chi],blackdp[chi])
    blackdp[par]=count
print(n-max(whitedp[0],blackdp[0]))
0