結果

問題 No.2427 Tree Distance Two
ユーザー 👑 timitimi
提出日時 2023-08-18 21:39:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 872 ms / 2,000 ms
コード長 658 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 184,748 KB
最終ジャッジ日時 2024-05-06 03:34:48
合計ジャッジ時間 14,663 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,376 KB
testcase_01 AC 39 ms
53,760 KB
testcase_02 AC 38 ms
53,760 KB
testcase_03 AC 854 ms
161,408 KB
testcase_04 AC 41 ms
53,248 KB
testcase_05 AC 872 ms
161,152 KB
testcase_06 AC 40 ms
53,376 KB
testcase_07 AC 519 ms
184,748 KB
testcase_08 AC 624 ms
170,112 KB
testcase_09 AC 581 ms
170,240 KB
testcase_10 AC 593 ms
170,496 KB
testcase_11 AC 598 ms
166,652 KB
testcase_12 AC 723 ms
163,848 KB
testcase_13 AC 833 ms
165,012 KB
testcase_14 AC 395 ms
167,680 KB
testcase_15 AC 47 ms
53,760 KB
testcase_16 AC 48 ms
54,016 KB
testcase_17 AC 46 ms
53,632 KB
testcase_18 AC 43 ms
54,272 KB
testcase_19 AC 44 ms
53,504 KB
testcase_20 AC 119 ms
78,208 KB
testcase_21 AC 125 ms
79,232 KB
testcase_22 AC 104 ms
77,696 KB
testcase_23 AC 94 ms
77,312 KB
testcase_24 AC 116 ms
78,208 KB
testcase_25 AC 243 ms
97,536 KB
testcase_26 AC 521 ms
128,768 KB
testcase_27 AC 373 ms
113,536 KB
testcase_28 AC 779 ms
154,624 KB
testcase_29 AC 691 ms
145,152 KB
testcase_30 AC 508 ms
125,312 KB
testcase_31 AC 351 ms
109,952 KB
testcase_32 AC 492 ms
126,976 KB
testcase_33 AC 451 ms
120,960 KB
testcase_34 AC 215 ms
89,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

##N,K=map(int, input().split())
#A=list(map(int, input().split()))
N=int(input())
D=[[]for _ in range(N)]
C=[[]for _ in range(N)]
for i in range(N-1):
  u,v=map(int, input().split())
  u-=1;v-=1
  D[u].append(v);D[v].append(u)
from collections import deque
d=deque()
d.append(0)
E=[-1]*N;P=[-1]*N
E[0]=0 
while d:
  now=d.popleft()
  for nex in D[now]:
    if E[nex]==-1:
      d.append(nex)
      E[nex]=E[now]+1 
      P[nex]=now
      C[now].append(nex)
CC=[]
for i in range(N):
  CC.append(len(C[i]))
  
for i in range(N):
  ans=0
  if E[i]>1:
    ans+=1 
  if E[i]>0:
    p=P[i]
    ans+=len(C[p])-1 
  CD=C[i]
  for c in CD:
    ans+=CC[c]
  print(ans)
0