結果

問題 No.1103 Directed Length Sum
ユーザー Ldio03Ldio03
提出日時 2020-05-06 01:17:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 678 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 86,624 KB
実行使用メモリ 263,740 KB
最終ジャッジ日時 2023-09-09 19:33:33
合計ジャッジ時間 17,729 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,100 KB
testcase_01 AC 70 ms
71,184 KB
testcase_02 WA -
testcase_03 AC 719 ms
263,740 KB
testcase_04 AC 1,020 ms
174,856 KB
testcase_05 AC 1,836 ms
232,176 KB
testcase_06 AC 665 ms
145,960 KB
testcase_07 AC 212 ms
92,828 KB
testcase_08 AC 285 ms
102,192 KB
testcase_09 AC 165 ms
86,612 KB
testcase_10 AC 370 ms
110,596 KB
testcase_11 AC 1,132 ms
195,100 KB
testcase_12 AC 677 ms
146,344 KB
testcase_13 AC 383 ms
112,752 KB
testcase_14 AC 157 ms
83,932 KB
testcase_15 AC 572 ms
125,588 KB
testcase_16 AC 1,269 ms
187,680 KB
testcase_17 AC 1,336 ms
201,596 KB
testcase_18 AC 363 ms
110,140 KB
testcase_19 AC 1,183 ms
173,360 KB
testcase_20 AC 181 ms
88,988 KB
testcase_21 AC 270 ms
99,136 KB
testcase_22 AC 959 ms
168,756 KB
testcase_23 AC 582 ms
136,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#n = 頂点数,edge = 隣接リスト
n=int(input())
edge=[[] for i in range(n)]
isroot=[True]*n
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1;b-=1
    edge[a].append(b)
    isroot[b]=False
Root=0
for i in range(n):
    if isroot[i]:Root=i;break   
order = []
par = [-1]*n
tank = [Root]
depth=[0]*n
while tank:
    pele = tank.pop()
    order.append(pele)
    for e in edge[pele]:
        if e == par[pele]:
            continue
        tank.append(e)
        par[e] = pele
        depth[e]=depth[pele]+1
size = [1]*n
for e in order[::-1]:
    if e == Root:
        break
    size[par[e]] += size[e]
ans=0
for i in range(n):
    ans+=size[i]*depth[i]
print(ans)
0