結果

問題 No.2638 Initial fare
ユーザー tipstar0125tipstar0125
提出日時 2024-02-20 13:21:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 291 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 88,724 KB
最終ジャッジ日時 2024-02-20 13:21:33
合計ジャッジ時間 5,939 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,460 KB
testcase_01 AC 28 ms
53,456 KB
testcase_02 AC 29 ms
53,460 KB
testcase_03 AC 30 ms
53,460 KB
testcase_04 AC 166 ms
88,644 KB
testcase_05 AC 173 ms
88,720 KB
testcase_06 AC 29 ms
53,460 KB
testcase_07 AC 164 ms
88,692 KB
testcase_08 AC 166 ms
88,144 KB
testcase_09 AC 200 ms
88,708 KB
testcase_10 AC 185 ms
88,724 KB
testcase_11 AC 32 ms
53,460 KB
testcase_12 AC 177 ms
88,672 KB
testcase_13 AC 162 ms
87,820 KB
testcase_14 AC 181 ms
88,704 KB
testcase_15 AC 177 ms
88,724 KB
testcase_16 AC 30 ms
53,460 KB
testcase_17 AC 206 ms
88,648 KB
testcase_18 AC 178 ms
88,628 KB
testcase_19 AC 184 ms
88,660 KB
testcase_20 AC 193 ms
88,652 KB
testcase_21 AC 178 ms
88,652 KB
testcase_22 AC 35 ms
53,460 KB
testcase_23 AC 175 ms
88,676 KB
testcase_24 AC 197 ms
88,724 KB
testcase_25 AC 32 ms
53,460 KB
testcase_26 AC 184 ms
88,724 KB
testcase_27 AC 197 ms
88,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
degs=[0 for _ in range(N)]
UV=[]
for _ in range(N-1):
    u,v=map(int,input().split())
    u-=1
    v-=1
    UV.append((u,v))
    degs[u]+=1
    degs[v]+=1

ans=N-1
for i in range(N):
    ans+=degs[i]*(degs[i]-1)//2
for (u,v) in UV:
    ans+=(degs[u]-1)*(degs[v]-1)
print(ans)
0