結果

問題 No.2677 Minmax Independent Set
ユーザー ゼットゼット
提出日時 2024-03-15 23:19:40
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,608 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 257,680 KB
最終ジャッジ日時 2024-03-15 23:20:52
合計ジャッジ時間 63,647 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
55,604 KB
testcase_01 AC 41 ms
55,604 KB
testcase_02 AC 43 ms
55,604 KB
testcase_03 AC 42 ms
55,604 KB
testcase_04 AC 42 ms
55,604 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 AC 1,545 ms
253,164 KB
testcase_11 AC 1,544 ms
253,800 KB
testcase_12 AC 1,120 ms
228,196 KB
testcase_13 AC 1,924 ms
242,660 KB
testcase_14 AC 1,867 ms
253,848 KB
testcase_15 AC 1,999 ms
251,192 KB
testcase_16 AC 1,951 ms
232,052 KB
testcase_17 AC 1,961 ms
232,572 KB
testcase_18 AC 1,295 ms
176,564 KB
testcase_19 AC 1,477 ms
195,004 KB
testcase_20 AC 601 ms
119,252 KB
testcase_21 AC 1,633 ms
207,364 KB
testcase_22 AC 292 ms
89,988 KB
testcase_23 AC 88 ms
76,632 KB
testcase_24 AC 49 ms
57,660 KB
testcase_25 AC 45 ms
55,604 KB
testcase_26 AC 49 ms
57,660 KB
testcase_27 AC 75 ms
72,732 KB
testcase_28 AC 1,365 ms
252,844 KB
testcase_29 AC 1,969 ms
230,480 KB
testcase_30 AC 42 ms
55,604 KB
testcase_31 AC 42 ms
55,604 KB
testcase_32 AC 43 ms
55,604 KB
testcase_33 AC 44 ms
55,604 KB
testcase_34 AC 44 ms
55,604 KB
testcase_35 AC 47 ms
55,604 KB
testcase_36 AC 49 ms
57,660 KB
testcase_37 AC 57 ms
61,760 KB
testcase_38 AC 98 ms
76,812 KB
testcase_39 AC 155 ms
79,000 KB
testcase_40 AC 182 ms
80,660 KB
testcase_41 AC 225 ms
82,436 KB
testcase_42 AC 250 ms
87,176 KB
testcase_43 AC 364 ms
96,992 KB
testcase_44 AC 574 ms
115,720 KB
testcase_45 AC 1,046 ms
152,860 KB
testcase_46 TLE -
testcase_47 TLE -
testcase_48 TLE -
testcase_49 TLE -
testcase_50 AC 599 ms
153,984 KB
testcase_51 AC 168 ms
82,936 KB
testcase_52 AC 1,237 ms
225,120 KB
testcase_53 AC 1,103 ms
218,264 KB
testcase_54 AC 173 ms
81,796 KB
testcase_55 AC 1,654 ms
257,496 KB
testcase_56 AC 1,688 ms
257,680 KB
testcase_57 AC 1,717 ms
251,052 KB
testcase_58 AC 1,715 ms
255,140 KB
testcase_59 AC 1,713 ms
252,368 KB
testcase_60 AC 1,009 ms
238,968 KB
testcase_61 AC 978 ms
230,948 KB
testcase_62 AC 953 ms
231,460 KB
testcase_63 AC 922 ms
232,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
G=[[] for i in range(N)]
from collections import deque
for i in range(N-1):
  a,b=map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
dp1=[[] for i in range(N)]
dp2=[[] for i in range(N)]
c=[[0]*2 for i in range(N)]
dist=[-1]*N
dist[0]=0
S=deque()
S.append(0)
while S:
  x=S.pop()
  for y in G[x]:
    if dist[y]>=0:
      continue
    dist[y]=dist[x]+1
    S.append(y)
L=[]
for i in range(N):
  L.append((dist[i],i))
L.sort(reverse=True)
for i in range(N):
  x=L[i][1]
  k1=0
  k2=1
  u1=[0]*(len(G[x]))
  u2=[0]*(len(G[x]))
  for j in range(len(G[x])):
    y=G[x][j]
    if dist[y]<dist[x]:
      continue
    u1[j]=c[y][0]
    u2[j]=max(c[y])
    k1+=u2[j]
    k2+=u1[j]
  dp1[x]=u1[:]
  dp2[x]=u2[:]
  c[x][0]=k1
  c[x][1]=k2
S=deque()
S.append(0)
T=[{} for i in range(N)]
for i in range(N):
  for j in range(len(G[i])):
    T[i][G[i][j]]=j
while S:
  x=S.pop()
  l1=[0]*(len(G[x]))
  r1=[0]*(len(G[x]))
  l2=[0]*(len(G[x]))
  r2=[0]*(len(G[x]))
  for j in range(len(G[x])):
    l1[j]=dp1[x][j]
    l2[j]=dp2[x][j]
    r1[j]=dp1[x][j]
    r2[j]=dp2[x][j]
  for j in range(1,len(G[x])):
    l1[j]+=l1[j-1]
    l2[j]+=l2[j-1]
  for j in range(len(G[x])-2,-1,-1):
    r1[j]+=r1[j+1]
    r2[j]+=r2[j+1]
  for j in range(len(G[x])):
    y=G[x][j]
    if dist[y]<dist[x]:
      continue
    w1=0
    w2=1
    if j>0:
      w1+=l2[j-1]
      w2+=l1[j-1]
    if j<len(G[x])-1:
      w1+=r2[j+1]
      w2+=r1[j+1]
    pos=T[y][x]
    dp1[y][pos]=w1
    dp2[y][pos]=max(w2,w1)
    S.append(y)
result=10**10
for i in range(N):
  ans=sum(dp1[i])+1
  result=min(result,ans)
print(result)
0