結果

問題 No.2638 Initial fare
ユーザー KoiKoi
提出日時 2024-02-19 21:37:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 358 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 106,668 KB
最終ジャッジ日時 2024-02-19 21:37:33
合計ジャッジ時間 7,314 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,460 KB
testcase_01 AC 30 ms
53,460 KB
testcase_02 AC 31 ms
53,460 KB
testcase_03 AC 31 ms
53,460 KB
testcase_04 AC 319 ms
99,596 KB
testcase_05 AC 309 ms
100,428 KB
testcase_06 AC 43 ms
53,460 KB
testcase_07 AC 296 ms
102,072 KB
testcase_08 AC 235 ms
104,124 KB
testcase_09 AC 267 ms
104,696 KB
testcase_10 AC 253 ms
106,668 KB
testcase_11 AC 32 ms
53,460 KB
testcase_12 AC 309 ms
102,308 KB
testcase_13 AC 225 ms
101,824 KB
testcase_14 AC 266 ms
106,064 KB
testcase_15 AC 259 ms
105,616 KB
testcase_16 AC 34 ms
53,460 KB
testcase_17 AC 320 ms
102,672 KB
testcase_18 AC 235 ms
102,780 KB
testcase_19 AC 297 ms
102,040 KB
testcase_20 AC 291 ms
101,524 KB
testcase_21 AC 321 ms
101,012 KB
testcase_22 AC 32 ms
53,460 KB
testcase_23 AC 320 ms
98,984 KB
testcase_24 AC 333 ms
99,788 KB
testcase_25 AC 33 ms
53,460 KB
testcase_26 AC 342 ms
99,792 KB
testcase_27 AC 309 ms
99,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
G=[[] for _ in range(N)]
for _ in range(N-1):
    u,v=map(int,input().split())
    G[u-1].append(v-1)
    G[v-1].append(u-1)
Two=[0]*N
ans=0
for i in range(N):
    ans+=len(G[i])
    for q in G[i]:
        Two[i]+=(len(G[q])-1)
for i in range(N):
    ans+=Two[i]
    for q in G[i]:
        ans+=Two[q]
        ans-=(len(G[i])-1)

print(ans//2)
0