結果

問題 No.1098 LCAs
ユーザー marroncastlemarroncastle
提出日時 2020-06-26 22:37:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 408 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 10,824 KB
実行使用メモリ 34,984 KB
最終ジャッジ日時 2023-09-18 06:09:09
合計ジャッジ時間 10,871 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,908 KB
testcase_01 AC 15 ms
7,844 KB
testcase_02 AC 16 ms
7,940 KB
testcase_03 AC 16 ms
7,784 KB
testcase_04 AC 15 ms
7,844 KB
testcase_05 AC 15 ms
7,940 KB
testcase_06 AC 15 ms
7,828 KB
testcase_07 AC 15 ms
7,784 KB
testcase_08 AC 15 ms
7,824 KB
testcase_09 AC 15 ms
7,848 KB
testcase_10 AC 15 ms
7,756 KB
testcase_11 AC 15 ms
7,900 KB
testcase_12 AC 15 ms
7,964 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(ans,edge,v):
  if len(edge[v])==0:
    ans[v] = 1
    return 1
  cnt = 1
  for w in edge[v]:
    a = dfs(ans,edge,w)
    ans[v] -= a*a
    cnt += a
  ans[v] += cnt*cnt
  return cnt

def solve():
  N = int(input())
  edge = [[] for _ in range(N)]
  for _ in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
  ans = [0]*N
  dfs(ans,edge,0)
  return ans
print(*solve(),sep='\n')
0