結果

問題 No.1098 LCAs
ユーザー marroncastlemarroncastle
提出日時 2020-09-13 05:24:23
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 571 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 845,072 KB
最終ジャッジ日時 2023-08-30 23:52:48
合計ジャッジ時間 13,554 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,532 KB
testcase_01 AC 71 ms
71,424 KB
testcase_02 AC 71 ms
71,176 KB
testcase_03 AC 71 ms
71,624 KB
testcase_04 AC 71 ms
71,180 KB
testcase_05 AC 71 ms
71,176 KB
testcase_06 AC 72 ms
71,312 KB
testcase_07 AC 71 ms
71,268 KB
testcase_08 AC 71 ms
71,136 KB
testcase_09 AC 71 ms
71,184 KB
testcase_10 AC 72 ms
71,340 KB
testcase_11 AC 72 ms
71,292 KB
testcase_12 AC 72 ms
71,340 KB
testcase_13 AC 85 ms
76,456 KB
testcase_14 AC 84 ms
76,212 KB
testcase_15 AC 84 ms
76,412 KB
testcase_16 AC 82 ms
75,792 KB
testcase_17 AC 86 ms
76,292 KB
testcase_18 AC 446 ms
111,084 KB
testcase_19 AC 451 ms
110,936 KB
testcase_20 AC 456 ms
110,776 KB
testcase_21 AC 456 ms
110,760 KB
testcase_22 AC 455 ms
111,236 KB
testcase_23 AC 371 ms
112,732 KB
testcase_24 AC 365 ms
113,016 KB
testcase_25 AC 327 ms
113,704 KB
testcase_26 AC 331 ms
112,648 KB
testcase_27 AC 327 ms
113,212 KB
testcase_28 MLE -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

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