結果

問題 No.2638 Initial fare
ユーザー hato336hato336
提出日時 2024-02-19 21:58:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 475 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 131,392 KB
最終ジャッジ日時 2024-02-19 21:58:51
合計ジャッジ時間 10,933 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
85,048 KB
testcase_01 AC 123 ms
85,048 KB
testcase_02 AC 123 ms
85,048 KB
testcase_03 AC 125 ms
85,048 KB
testcase_04 AC 458 ms
124,156 KB
testcase_05 AC 437 ms
124,900 KB
testcase_06 AC 121 ms
85,048 KB
testcase_07 AC 442 ms
127,092 KB
testcase_08 AC 367 ms
124,580 KB
testcase_09 AC 395 ms
131,188 KB
testcase_10 AC 412 ms
131,392 KB
testcase_11 AC 121 ms
85,048 KB
testcase_12 AC 413 ms
126,908 KB
testcase_13 AC 348 ms
124,708 KB
testcase_14 AC 418 ms
129,668 KB
testcase_15 AC 389 ms
131,004 KB
testcase_16 AC 133 ms
88,248 KB
testcase_17 AC 406 ms
126,840 KB
testcase_18 AC 396 ms
126,884 KB
testcase_19 AC 443 ms
126,552 KB
testcase_20 AC 452 ms
125,892 KB
testcase_21 AC 437 ms
125,452 KB
testcase_22 AC 123 ms
85,048 KB
testcase_23 AC 437 ms
123,576 KB
testcase_24 AC 475 ms
124,256 KB
testcase_25 AC 124 ms
85,048 KB
testcase_26 AC 441 ms
124,128 KB
testcase_27 AC 471 ms
124,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
n = int(input())
edge = [[] for i in range(n)]
nyuji = [0 for i in range(n)]
e = []
for i in range(n-1):
    u,v = map(int,input().split())
    u-=1
    v-=1
    edge[u].append(v)
    edge[v].append(u)
    nyuji[u] += 1
    nyuji[v] += 1
    e.append((u,v))
ans = 0
for u,v in e:
    ans += (nyuji[u]-1) * (nyuji[v] - 1 )
    ans += 1
for i in range(n):
    ans += nyuji[i]*(nyuji[i]-1)//2
print(ans)
0