結果

問題 No.2638 Initial fare
ユーザー shobonvipshobonvip
提出日時 2024-02-11 16:58:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 746 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 211,028 KB
実行使用メモリ 55,028 KB
最終ジャッジ日時 2024-02-11 16:58:27
合計ジャッジ時間 13,422 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 2 ms
6,676 KB
testcase_07 RE -
testcase_08 AC 187 ms
27,616 KB
testcase_09 RE -
testcase_10 AC 185 ms
29,928 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 RE -
testcase_13 AC 163 ms
26,368 KB
testcase_14 RE -
testcase_15 AC 192 ms
29,948 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
	int n; cin >> n;
	vector ikeru(n, vector<int>(0));
	for (int i=0; i<n-1; i++){
		int u, v; cin >> u >> v;
		u--; v--;
		ikeru[u].push_back(v);
		ikeru[v].push_back(u);
	}

	long long ans = 0;
	vector dp(n, vector<long long>(4));
	vector<int> mx(n, 0);

	auto dfs = [&](auto self, int i, int p) -> void {
		dp[i][0] = 1;
		mx[i] = 1;
		for (int j: ikeru[i]){
			if (j == p) continue;
			self(self, j, i);
			for (int x=0; x<mx[i]; x++){
				for (int y=0; y<mx[j]; y++){
					if (x+y+1 > 3) break;
					ans += dp[i][x] * dp[j][y];
				}
			}
			for (int x=0; x<mx[j]; x++){
				dp[i][x+1] += dp[j][x];
			}
			mx[i] = max(mx[i], mx[j]+1);
		}
	};

	dfs(dfs, 0, -1);
	cout << ans << '\n';
}
0