結果

問題 No.1098 LCAs
ユーザー marroncastlemarroncastle
提出日時 2020-06-26 22:51:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 503 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 45,848 KB
最終ジャッジ日時 2023-09-18 06:47:10
合計ジャッジ時間 13,750 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,820 KB
testcase_01 AC 16 ms
7,932 KB
testcase_02 AC 16 ms
7,828 KB
testcase_03 AC 16 ms
7,780 KB
testcase_04 AC 16 ms
7,836 KB
testcase_05 AC 16 ms
7,864 KB
testcase_06 AC 16 ms
7,768 KB
testcase_07 AC 16 ms
7,844 KB
testcase_08 AC 16 ms
7,804 KB
testcase_09 AC 16 ms
7,852 KB
testcase_10 AC 15 ms
7,828 KB
testcase_11 AC 16 ms
7,788 KB
testcase_12 AC 16 ms
7,948 KB
testcase_13 AC 19 ms
8,180 KB
testcase_14 AC 20 ms
8,224 KB
testcase_15 AC 19 ms
8,316 KB
testcase_16 AC 20 ms
8,368 KB
testcase_17 AC 19 ms
8,356 KB
testcase_18 AC 1,002 ms
44,944 KB
testcase_19 AC 988 ms
45,020 KB
testcase_20 AC 987 ms
44,836 KB
testcase_21 AC 981 ms
44,900 KB
testcase_22 AC 978 ms
44,868 KB
testcase_23 AC 851 ms
40,000 KB
testcase_24 AC 851 ms
39,948 KB
testcase_25 AC 824 ms
39,596 KB
testcase_26 AC 867 ms
45,740 KB
testcase_27 AC 866 ms
45,848 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(ans,edge,visited,v):
  cnt = 1
  for w in edge[v]:
    if visited[w]==False:
      visited[w]=True
      a = dfs(ans,edge,visited,w)
      ans[v] -= a*a
      cnt += a
  ans[v] += cnt**2
  return cnt

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