結果

問題 No.1098 LCAs
ユーザー marroncastlemarroncastle
提出日時 2020-09-13 05:25:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 926 ms / 2,000 ms
コード長 571 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 86,860 KB
最終ジャッジ日時 2023-08-30 23:54:13
合計ジャッジ時間 11,785 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,880 KB
testcase_01 AC 15 ms
7,764 KB
testcase_02 AC 16 ms
7,784 KB
testcase_03 AC 16 ms
7,816 KB
testcase_04 AC 15 ms
7,964 KB
testcase_05 AC 16 ms
7,776 KB
testcase_06 AC 15 ms
7,836 KB
testcase_07 AC 15 ms
7,848 KB
testcase_08 AC 15 ms
7,824 KB
testcase_09 AC 15 ms
7,812 KB
testcase_10 AC 16 ms
7,912 KB
testcase_11 AC 15 ms
7,864 KB
testcase_12 AC 16 ms
7,836 KB
testcase_13 AC 18 ms
8,264 KB
testcase_14 AC 18 ms
8,384 KB
testcase_15 AC 17 ms
8,196 KB
testcase_16 AC 18 ms
8,320 KB
testcase_17 AC 17 ms
8,268 KB
testcase_18 AC 651 ms
44,868 KB
testcase_19 AC 650 ms
44,848 KB
testcase_20 AC 646 ms
44,956 KB
testcase_21 AC 648 ms
44,972 KB
testcase_22 AC 657 ms
44,876 KB
testcase_23 AC 536 ms
39,852 KB
testcase_24 AC 539 ms
39,836 KB
testcase_25 AC 518 ms
39,636 KB
testcase_26 AC 547 ms
45,768 KB
testcase_27 AC 559 ms
45,892 KB
testcase_28 AC 925 ms
83,448 KB
testcase_29 AC 912 ms
86,860 KB
testcase_30 AC 926 ms
83,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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