結果

問題 No.2638 Initial fare
ユーザー ramdosramdos
提出日時 2024-02-11 11:51:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,120 ms / 2,000 ms
コード長 326 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 51,584 KB
最終ジャッジ日時 2024-04-25 05:10:41
合計ジャッジ時間 22,600 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,624 KB
testcase_01 AC 32 ms
10,624 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 1,061 ms
49,408 KB
testcase_05 AC 1,099 ms
51,456 KB
testcase_06 AC 31 ms
10,624 KB
testcase_07 AC 1,107 ms
50,816 KB
testcase_08 AC 1,011 ms
48,000 KB
testcase_09 AC 1,086 ms
51,200 KB
testcase_10 AC 1,093 ms
51,584 KB
testcase_11 AC 30 ms
10,624 KB
testcase_12 AC 1,089 ms
50,176 KB
testcase_13 AC 938 ms
46,080 KB
testcase_14 AC 1,106 ms
51,072 KB
testcase_15 AC 1,111 ms
51,456 KB
testcase_16 AC 31 ms
10,752 KB
testcase_17 AC 1,040 ms
49,536 KB
testcase_18 AC 1,040 ms
48,896 KB
testcase_19 AC 1,085 ms
49,792 KB
testcase_20 AC 1,098 ms
49,536 KB
testcase_21 AC 1,085 ms
49,536 KB
testcase_22 AC 32 ms
10,624 KB
testcase_23 AC 1,092 ms
50,176 KB
testcase_24 AC 1,120 ms
51,456 KB
testcase_25 AC 32 ms
10,624 KB
testcase_26 AC 1,101 ms
51,584 KB
testcase_27 AC 1,107 ms
51,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
e=[list(map(lambda x: int(x)-1,input().split())) for i in range(N-1)]
v=[0 for i in range(N)]
for i in range(N-1):
    v[e[i][0]]+=1
    v[e[i][1]]+=1
ans = N-1 # distance=1
for i in range(N): #distance=2
    ans+=v[i]*(v[i]-1)//2
for i in range(N-1): #distance=3
  ans+=(v[e[i][0]]-1)*(v[e[i][1]]-1)
print(ans)
0