結果
問題 | No.1098 LCAs |
ユーザー | ttr |
提出日時 | 2020-06-26 23:19:45 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 852 bytes |
コンパイル時間 | 274 ms |
コンパイル使用メモリ | 87,132 KB |
実行使用メモリ | 122,104 KB |
最終ジャッジ日時 | 2023-09-18 07:59:07 |
合計ジャッジ時間 | 13,202 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 92 ms
71,612 KB |
testcase_01 | AC | 87 ms
71,580 KB |
testcase_02 | AC | 87 ms
71,524 KB |
testcase_03 | AC | 89 ms
71,680 KB |
testcase_04 | AC | 88 ms
71,724 KB |
testcase_05 | AC | 91 ms
71,732 KB |
testcase_06 | AC | 89 ms
71,560 KB |
testcase_07 | AC | 87 ms
71,748 KB |
testcase_08 | AC | 87 ms
71,676 KB |
testcase_09 | AC | 88 ms
71,688 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
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 | AC | 471 ms
121,952 KB |
testcase_26 | AC | 464 ms
120,616 KB |
testcase_27 | AC | 451 ms
120,936 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
ソースコード
from collections import deque N = int(input()) E = [[] for _ in range(N)] for _ in range(N-1): u,v = map(int, input().split()) E[u-1].append(v-1) E[v-1].append(u-1) parent = [-1]*N used = [-1]*N q = deque() q.append(0) used[0] = 0 while q: u = q.popleft() for v in E[u]: if used[v] >= 0: continue q.append(v) parent[v] = u used[v] = used[u]+1 num = [0]*N for i in range(N): used[i] = (used[i], i) used.sort(reverse=True) for u in used: if u[1] == 0: continue num[parent[u[1]]] += num[u[1]]+1 for i in range(N): ans = 2*num[i]+1 cnt = 0 for v in E[i]: if parent[i] == v: continue cnt += 1 ans += cnt*(cnt-1) for v in E[i]: if parent[i] == v: continue ans += 2*num[v]*(cnt-1) print(ans)