結果

問題 No.417 チューリップバブル
ユーザー zawakasuzawakasu
提出日時 2023-01-31 11:44:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,911 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 213,240 KB
実行使用メモリ 6,472 KB
最終ジャッジ日時 2023-09-13 05:43:31
合計ジャッジ時間 7,529 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
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 -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define all(x) begin(x), end(x)
#define times(x) for (int _ = 0 ; _ < (int)(x) ; _++)

using i32 = int;
using i64 = long long;
using ld = long double;
using usize = std::size_t;

template <class T1, class T2>
inline bool chmax(T1 &a, const T2 &b) { return a < b and (a = b, true); }
template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) { return a > b and (a = b, true); }

constexpr i64 supl = (std::numeric_limits<i64>::max() >> 1) - 100;
constexpr i32 supi = (std::numeric_limits<i32>::max() >> 1) - 100;



namespace zawa::input {

template <typename T> 
void in(T& res) { std::cin >> res; }

template <typename Head, typename... Tail>
void in(Head& head, Tail&... tail) { in(head); in(tail...); }

template <typename T, typename U>
void in(std::pair<T, U>& res) { in(res.first); in(res.second); }

template <typename T>
void in(std::vector<T>& res) { for (auto& r : res) { in(r); } }

} // namespace zawa::input
using zawa::input::in;



namespace zawa::output {

void out() { 
    std::cout << std::endl; 
}

template <class T>
void out(const T& a) { 
    std::cout << a << std::endl; 
}

template <class T>
void out(const std::vector<T>& as) { 
    for (std::size_t i = 0 ; i < as.size() ; i++) { 
        std::cout << as[i] << (i + 1 == as.size() ? '\n' : ' '); 
    } 
}

template <class Head, class... Tail>
void out(const Head& head, const Tail&... tail) { 
    std::cout << head; 
    if (sizeof...(tail)) { 
        std::cout << ' '; 
    } 
    out(tail...);
}

void yesno(bool flag, std::string yes = "Yes", std::string no = "No") {
    std::cout << (flag ? yes : no) << std::endl;
}

} // namespace zawa::output
using zawa::output::out;
using zawa::output::yesno;

// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
// using mint = atcoder::modint1000000007;

// #include "src/template/accum1d.hpp"
// #include "src/template/binary-search.hpp"
// #include "src/template/binary-search-ld.hpp"
// #include "src/algorithm/compression.hpp"
// #include "src/algorithm/RLE.hpp"

// #include "src/graph/Read-Graph.hpp"


namespace zawa {

template <typename T>
std::vector<std::vector<std::pair<int, T>>> read_weighted_graph(int n, int m, bool undirect = true, bool minus = true) {
    std::vector<std::vector<std::pair<int, T>>> res(n, std::vector(0, std::pair<int, T>()));
    for (int _ = 0 ; _ < m ; _++) {
        int u, v; std::cin >> u >> v;
        T c; std::cin >> c;
        res[u - minus].emplace_back(v - minus, c);
        if (undirect) {
            res[v - minus].emplace_back(u - minus, c);
        }
    }
    return res;
}

template <typename T>
std::vector<std::vector<std::pair<int, T>>> read_weighted_tree(int n, bool undirect = true) {
    return read_weighted_graph<T>(n, n - 1, undirect);
}

} // namespace zawa

using namespace std;

void main_() {
	i32 n, m; in(n, m);
	vector us(n, 0); in(us);
	vector G(n, vector(0, pair(0, 0)));
	times(n - 1) {
		i32 u, v, c; in(u, v, c);
		G[u].emplace_back(v, c);
		G[v].emplace_back(u, c);
	}
	vector dp(n, vector(m + 1, -supl));
	auto rec = [&](auto rec, i32 v, i32 p) -> void {
		for (usize i = 0 ; i < G[v].size() ; i++) {
			if (G[v][i].first == p) {
				G[v].erase(G[v].begin() + i);
				break;
			}
		}
		for (auto [x, _] : G[v]) {
			rec(rec, x, v);
		}
		dp[v][0] = us[v];
		for (auto [x, c] : G[v]) {
			vector nxt = dp[v];
			for (i32 i = 0 ; i <= m ; i++) {
				if (dp[v][i] == -supi) {
					continue;
				}
				for (i32 j = 0 ; j + i + 2 * c <= m ; j++) {
					if (dp[x][j] == -supi) {
						continue;
					}
					chmax(nxt[j + i + 2 * c], dp[v][i] + dp[x][j]);	
				}
			}
			dp[v] = move(nxt);
		}
	};
	rec(rec, 0, -1);
	for (i32 i = 0 ; i <= m ; i++) {
		if (dp[0][i] > 0) {
			out(i, dp[0][i]);
		}
	}
	out(*max_element(all(dp[0])));
}

i32 main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);

	main_();

	return 0;
}
0