結果

問題 No.2638 Initial fare
ユーザー nikoro256nikoro256
提出日時 2024-02-19 21:31:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 277 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 90,468 KB
最終ジャッジ日時 2024-04-09 04:29:06
合計ジャッジ時間 7,056 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,012 KB
testcase_01 AC 34 ms
52,064 KB
testcase_02 AC 35 ms
52,548 KB
testcase_03 AC 36 ms
52,548 KB
testcase_04 AC 201 ms
89,044 KB
testcase_05 AC 211 ms
89,120 KB
testcase_06 AC 35 ms
53,048 KB
testcase_07 AC 201 ms
88,836 KB
testcase_08 AC 193 ms
89,300 KB
testcase_09 AC 199 ms
88,988 KB
testcase_10 AC 202 ms
90,468 KB
testcase_11 AC 34 ms
52,800 KB
testcase_12 AC 201 ms
89,052 KB
testcase_13 AC 181 ms
88,220 KB
testcase_14 AC 203 ms
88,976 KB
testcase_15 AC 201 ms
89,124 KB
testcase_16 AC 37 ms
53,096 KB
testcase_17 AC 199 ms
88,796 KB
testcase_18 AC 195 ms
89,032 KB
testcase_19 AC 202 ms
88,936 KB
testcase_20 AC 200 ms
88,924 KB
testcase_21 AC 203 ms
89,296 KB
testcase_22 AC 36 ms
52,896 KB
testcase_23 AC 202 ms
88,940 KB
testcase_24 AC 206 ms
89,120 KB
testcase_25 AC 36 ms
52,552 KB
testcase_26 AC 209 ms
89,124 KB
testcase_27 AC 211 ms
89,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
point=[0]*N
dat=[]
for _ in range(N-1):
    u,v=map(int,input().split())
    dat.append((u,v))
    point[u-1]+=1
    point[v-1]+=1
ans=0
ans2=0
for u,v in dat:
    ans+=1
    ans+=(point[u-1]-1)*(point[v-1]-1)
    ans2+=point[u-1]+point[v-1]-2
print(ans+ans2//2)
0