結果

問題 No.1488 Max Score of the Tree
ユーザー tkmst201tkmst201
提出日時 2021-06-13 21:11:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,519 bytes
コンパイル時間 2,565 ms
コンパイル使用メモリ 208,596 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-25 00:26:24
合計ジャッジ時間 4,726 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,384 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,388 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,384 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N, K;
	cin >> N >> K;
	vector<vector<pii>> g(N);
	vector<int> A(N - 1), B(N - 1), C(N - 1);
	REP(i, N - 1) {
		scanf("%d %d %d", &A[i], &B[i], &C[i]);
		--A[i]; --B[i];
		g[A[i]].emplace_back(B[i], i);
		g[B[i]].emplace_back(A[i], i);
	}
	auto D = C;
	
	auto dfs = [&](auto self, int u, int p, int pedge) -> int {
		int leaf = 0;
		for (auto [v, eidx] : g[u]) {
			if (v == p) continue;
			leaf += self(self, v, u, eidx);
		}
		if (leaf == 0) leaf = 1;
		if (p != -1) D[pedge] *= leaf;
		return leaf;
	};
	dfs(dfs, 0, -1, -1);
	
	int ans = 0;
	REP(i, N) {
		auto dfs2 = [&](auto self, int u, int p, int c, int d) -> void {
			chmax(ans, d);
			for (auto [v, eidx] : g[u]) {
				if (v == p) continue;
				const int nexc = c + C[eidx];
				if (nexc > K) break;
				self(self, v, u, nexc, d + D[eidx]);
			}
		};
		dfs2(dfs2, i, -1, 0, 0);
	}
	ans += accumulate(ALL(D), 0);
	cout << ans << endl;
}
0