結果

問題 No.2638 Initial fare
ユーザー chineristACchineristAC
提出日時 2024-02-19 22:08:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 346 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 104,680 KB
最終ジャッジ日時 2024-02-19 22:08:45
合計ジャッジ時間 7,267 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
56,240 KB
testcase_01 AC 41 ms
56,240 KB
testcase_02 AC 43 ms
56,240 KB
testcase_03 AC 40 ms
56,240 KB
testcase_04 AC 293 ms
98,992 KB
testcase_05 AC 321 ms
100,224 KB
testcase_06 AC 38 ms
56,240 KB
testcase_07 AC 301 ms
101,888 KB
testcase_08 AC 244 ms
103,180 KB
testcase_09 AC 240 ms
103,764 KB
testcase_10 AC 240 ms
104,192 KB
testcase_11 AC 39 ms
56,240 KB
testcase_12 AC 292 ms
101,836 KB
testcase_13 AC 202 ms
101,812 KB
testcase_14 AC 239 ms
104,648 KB
testcase_15 AC 253 ms
104,680 KB
testcase_16 AC 40 ms
56,240 KB
testcase_17 AC 283 ms
102,072 KB
testcase_18 AC 222 ms
102,688 KB
testcase_19 AC 283 ms
102,080 KB
testcase_20 AC 288 ms
101,048 KB
testcase_21 AC 278 ms
98,616 KB
testcase_22 AC 38 ms
56,240 KB
testcase_23 AC 323 ms
98,512 KB
testcase_24 AC 346 ms
99,072 KB
testcase_25 AC 39 ms
56,240 KB
testcase_26 AC 322 ms
99,328 KB
testcase_27 AC 290 ms
98,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import permutations
from heapq import heappop,heappush
from collections import deque
import random
import bisect

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N = int(input())
edge = [[] for v in range(N)]
for _ in range(N-1):
    u,v = mi()
    edge[u-1].append(v-1)
    edge[v-1].append(u-1)

res = N - 1

tmp2 = 0
for v in range(N):
    for nv in edge[v]:
        tmp2 += (len(edge[nv])-1)
res += tmp2//2

tmp3 = 0
for v in range(N):
    for nv in edge[v]:
        tmp3 += (len(edge[v])-1) * (len(edge[nv])-1)
res += tmp3//2

print(res)
0