結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,728 KB
testcase_01 AC 16 ms
7,792 KB
testcase_02 AC 16 ms
7,860 KB
testcase_03 AC 17 ms
7,776 KB
testcase_04 AC 16 ms
7,800 KB
testcase_05 AC 16 ms
7,964 KB
testcase_06 AC 15 ms
7,776 KB
testcase_07 AC 16 ms
7,800 KB
testcase_08 AC 16 ms
7,764 KB
testcase_09 AC 16 ms
7,944 KB
testcase_10 AC 16 ms
7,812 KB
testcase_11 AC 16 ms
7,732 KB
testcase_12 AC 16 ms
7,812 KB
testcase_13 AC 19 ms
8,420 KB
testcase_14 AC 19 ms
8,240 KB
testcase_15 AC 19 ms
8,384 KB
testcase_16 AC 19 ms
8,296 KB
testcase_17 AC 19 ms
8,308 KB
testcase_18 AC 993 ms
44,860 KB
testcase_19 AC 1,014 ms
44,992 KB
testcase_20 AC 989 ms
44,952 KB
testcase_21 AC 1,005 ms
44,856 KB
testcase_22 AC 1,009 ms
44,960 KB
testcase_23 AC 861 ms
40,020 KB
testcase_24 AC 864 ms
39,960 KB
testcase_25 AC 839 ms
39,616 KB
testcase_26 AC 883 ms
45,752 KB
testcase_27 AC 879 ms
45,900 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(ans,edge,visited,v):
  if len(edge[v])==0:
    ans[v] = 1
    return 1
  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*cnt
  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