結果

問題 No.2638 Initial fare
ユーザー shobonvipshobonvip
提出日時 2024-02-11 18:52:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 844 ms / 2,000 ms
コード長 317 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 27,264 KB
最終ジャッジ日時 2024-02-11 18:53:08
合計ジャッジ時間 16,981 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
9,984 KB
testcase_01 AC 30 ms
9,984 KB
testcase_02 AC 29 ms
9,984 KB
testcase_03 AC 27 ms
9,984 KB
testcase_04 AC 780 ms
26,368 KB
testcase_05 AC 806 ms
27,264 KB
testcase_06 AC 28 ms
9,984 KB
testcase_07 AC 780 ms
26,880 KB
testcase_08 AC 768 ms
25,856 KB
testcase_09 AC 792 ms
27,136 KB
testcase_10 AC 783 ms
27,264 KB
testcase_11 AC 28 ms
9,984 KB
testcase_12 AC 804 ms
26,752 KB
testcase_13 AC 694 ms
25,088 KB
testcase_14 AC 795 ms
27,136 KB
testcase_15 AC 844 ms
27,264 KB
testcase_16 AC 28 ms
9,984 KB
testcase_17 AC 736 ms
26,368 KB
testcase_18 AC 761 ms
26,240 KB
testcase_19 AC 793 ms
26,624 KB
testcase_20 AC 760 ms
26,496 KB
testcase_21 AC 782 ms
26,496 KB
testcase_22 AC 29 ms
9,984 KB
testcase_23 AC 808 ms
26,752 KB
testcase_24 AC 795 ms
27,264 KB
testcase_25 AC 28 ms
9,984 KB
testcase_26 AC 822 ms
27,264 KB
testcase_27 AC 810 ms
27,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
u = [0] * (n-1)
v = [0] * (n-1)
deg = [0] * n
for i in range(n-1):
	u[i], v[i] = map(int,input().split())
	u[i] -= 1
	v[i] -= 1
	deg[u[i]] += 1
	deg[v[i]] += 1

ans = n-1
for i in range(n-1):
	ans += (deg[u[i]] - 1) * (deg[v[i]] - 1)
for i in range(n):
	ans += deg[i] * (deg[i] - 1) // 2

print(ans) 
0