結果

問題 No.2638 Initial fare
ユーザー hayatroidhayatroid
提出日時 2024-02-19 21:31:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 413 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 51,476 KB
最終ジャッジ日時 2024-02-19 21:31:34
合計ジャッジ時間 4,130 ms
ジャッジサーバーID
(参考情報)
judge16 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
16,916 KB
testcase_01 AC 27 ms
10,112 KB
testcase_02 AC 27 ms
10,112 KB
testcase_03 AC 30 ms
10,112 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque


N = int(input())

G = [[] for _ in range(N)]
for _ in range(N - 1):
	u, v = map(int, input().split())
	u -= 1; v -= 1;
	G[u].append(v)
	G[v].append(u)

ans = 0
for i in range(N):
	bfs = deque()
	bfs.append(i)
	d = [-1] * N
	d[i] = 0
	while bfs:
		u = bfs.popleft()
		for v in G[u]:
			if d[u] < 3 and d[v] == -1:
				bfs.append(v)
				d[v] = d[u] + 1
				ans += 1

print(ans // 2)
0