結果

問題 No.2427 Tree Distance Two
ユーザー FromBooskaFromBooska
提出日時 2023-10-05 17:11:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 728 ms / 2,000 ms
コード長 381 bytes
コンパイル時間 485 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 129,336 KB
最終ジャッジ日時 2023-10-05 17:11:29
合計ジャッジ時間 19,988 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,680 KB
testcase_01 AC 101 ms
71,264 KB
testcase_02 AC 74 ms
71,156 KB
testcase_03 AC 702 ms
116,132 KB
testcase_04 AC 74 ms
71,312 KB
testcase_05 AC 728 ms
116,116 KB
testcase_06 AC 75 ms
71,256 KB
testcase_07 AC 561 ms
128,680 KB
testcase_08 AC 625 ms
127,964 KB
testcase_09 AC 560 ms
127,236 KB
testcase_10 AC 597 ms
129,336 KB
testcase_11 AC 598 ms
126,736 KB
testcase_12 AC 628 ms
124,084 KB
testcase_13 AC 680 ms
122,116 KB
testcase_14 AC 339 ms
114,392 KB
testcase_15 AC 75 ms
71,112 KB
testcase_16 AC 78 ms
71,340 KB
testcase_17 AC 76 ms
71,156 KB
testcase_18 AC 76 ms
71,428 KB
testcase_19 AC 75 ms
71,496 KB
testcase_20 AC 125 ms
78,232 KB
testcase_21 AC 138 ms
78,656 KB
testcase_22 AC 116 ms
78,444 KB
testcase_23 AC 117 ms
78,252 KB
testcase_24 AC 126 ms
78,604 KB
testcase_25 AC 234 ms
87,680 KB
testcase_26 AC 463 ms
100,652 KB
testcase_27 AC 356 ms
94,308 KB
testcase_28 AC 668 ms
113,416 KB
testcase_29 AC 593 ms
109,824 KB
testcase_30 AC 458 ms
100,888 KB
testcase_31 AC 341 ms
92,572 KB
testcase_32 AC 445 ms
100,124 KB
testcase_33 AC 397 ms
97,540 KB
testcase_34 AC 193 ms
84,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# distance 2であれば次数degreeから計算可能

N = int(input())
degree = [0]*(N+1)
edges = [[] for i in range(N+1)]
for i in range(N-1):
    u, v = map(int, input().split())
    degree[u] += 1
    degree[v] += 1
    edges[u].append(v)
    edges[v].append(u)
    
for i in range(1, N+1):
    ans = 0
    for nxt in edges[i]:
        ans += degree[nxt]-1
    print(ans)
    
0