結果

問題 No.417 チューリップバブル
ユーザー HachimoriHachimori
提出日時 2016-08-27 12:17:05
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,765 bytes
コンパイル時間 663 ms
コンパイル使用メモリ 65,028 KB
実行使用メモリ 41,552 KB
最終ジャッジ日時 2024-04-26 06:14:37
合計ジャッジ時間 4,861 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 7 ms
5,376 KB
testcase_21 AC 7 ms
5,376 KB
testcase_22 AC 6 ms
5,376 KB
testcase_23 AC 7 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 6 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 7 ms
5,376 KB
testcase_28 AC 8 ms
5,376 KB
testcase_29 AC 8 ms
5,376 KB
testcase_30 AC 10 ms
5,376 KB
testcase_31 AC 10 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 TLE -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#define dst first
#define time second 
using namespace std;
typedef pair<int, int> Edge;
const int NODE = 105;
const int TIME = 1005;


int nNode, limit;
int val[NODE];
vector<Edge> adj[NODE];

void read() {
    for (int i = 0; i < NODE; ++i) adj[i].clear();

    cin >> nNode >> limit;
    for (int i = 0; i < nNode; ++i) cin >> val[i];

    for (int i = 0; i < nNode - 1; ++i) {
        int s, t, c;
        cin >> s >> t >> c;
        adj[s].push_back(Edge(t, c));
        adj[t].push_back(Edge(s, c));
    }

    limit /= 2;
}


void rec(int prev, int curr, int dp[NODE][TIME]) {

    for (int i = 0; i < adj[curr].size(); ++i) {
        Edge &e = adj[curr][i];
        if (e.dst == prev) continue;
        rec(curr, e.dst, dp);
    }

    dp[curr][0] = val[curr];
    for (int i = 0; i < adj[curr].size(); ++i) {
        Edge &e = adj[curr][i];
        if (e.dst == prev) continue;

        for (int curUsedTime = limit; curUsedTime >= 0; --curUsedTime) {
            if (dp[curr][curUsedTime] == -1) continue;
            for (int nexUsedTime = limit - curUsedTime - e.time; nexUsedTime >= 0; --nexUsedTime) {
                if (dp[e.dst][nexUsedTime] == -1) continue;
                
                int nextValue = dp[curr][curUsedTime] + dp[e.dst][nexUsedTime];
                dp[curr][curUsedTime + nexUsedTime + e.time] = max(dp[curr][curUsedTime + nexUsedTime + e.time], nextValue);
            }
        }
    }
}


void work() {
    // dp[node][used time] := maximum value
    static int dp[NODE][TIME];
    memset(dp, -1, sizeof(dp));
    rec(-1, 0, dp);

    cout << *max_element(dp[0], dp[0] + limit + 1) << endl;
}


int main() {
    read();
    work();
    return 0;
}
0