結果

問題 No.2638 Initial fare
ユーザー vwxyzvwxyz
提出日時 2024-04-11 15:52:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,391 ms / 2,000 ms
コード長 335 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 59,368 KB
最終ジャッジ日時 2024-04-11 15:52:52
合計ジャッジ時間 27,373 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,880 KB
testcase_01 AC 33 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 29 ms
10,752 KB
testcase_04 AC 1,277 ms
55,808 KB
testcase_05 AC 1,387 ms
58,240 KB
testcase_06 AC 31 ms
10,752 KB
testcase_07 AC 1,265 ms
57,728 KB
testcase_08 AC 1,067 ms
55,168 KB
testcase_09 AC 1,264 ms
58,780 KB
testcase_10 AC 1,253 ms
59,368 KB
testcase_11 AC 28 ms
10,880 KB
testcase_12 AC 1,262 ms
56,928 KB
testcase_13 AC 1,090 ms
52,896 KB
testcase_14 AC 1,273 ms
58,944 KB
testcase_15 AC 1,154 ms
59,340 KB
testcase_16 AC 30 ms
10,752 KB
testcase_17 AC 1,228 ms
57,088 KB
testcase_18 AC 1,187 ms
56,832 KB
testcase_19 AC 1,330 ms
57,600 KB
testcase_20 AC 1,290 ms
57,088 KB
testcase_21 AC 1,332 ms
56,704 KB
testcase_22 AC 32 ms
10,752 KB
testcase_23 AC 1,336 ms
56,448 KB
testcase_24 AC 1,391 ms
57,728 KB
testcase_25 AC 31 ms
10,752 KB
testcase_26 AC 1,370 ms
57,856 KB
testcase_27 AC 1,320 ms
57,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
edges=[]
graph=[[] for x in range(N)]
for i in range(N-1):
    u,v=map(int,input().split())
    u-=1;v-=1
    edges.append((u,v))
    graph[u].append(v)
    graph[v].append(u)
ans=N-1
for x in range(N):
    ans+=len(graph[x])*(len(graph[x])-1)//2
for u,v in edges:
    ans+=(len(graph[u])-1)*(len(graph[v])-1)
print(ans)
0