結果

問題 No.2638 Initial fare
ユーザー ああいいああいい
提出日時 2024-02-23 22:25:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 678 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 154,216 KB
最終ジャッジ日時 2024-02-23 22:26:00
合計ジャッジ時間 16,074 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 40 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 38 ms
53,460 KB
testcase_07 WA -
testcase_08 AC 516 ms
138,672 KB
testcase_09 WA -
testcase_10 AC 491 ms
154,216 KB
testcase_11 AC 42 ms
53,460 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
	
dp = [[0] * 2 for _ in range(N)]
stack = [(0,-1),(~0,-1)]
ans = 0
while stack:
	now,p = stack.pop()
	if now < 0:
		now = ~now
		for v in G[now]:
			if v != p:
				stack.append((v,now))
				stack.append((~v,now))
	else:
		t1 = 0
		tt = 0
		t2 = 0
		for v in G[now]:
			if v != p:
				tt += 1
				dp[now][0] += 1
				dp[now][1] += dp[v][0]
				t1 = dp[v][0]
				t2 = dp[v][1]
				
				ans += 1 + dp[v][0] + dp[v][1]
		tmp = 0
		for v in G[now]:
			if v != p:
				tmp += (t1 - dp[v][0])
		ans += tmp + (tt - 1) * tt // 2
print(ans)
0