Submission #1213615

#TimeUsernameProblemLanguageResultExecution timeMemory
1213615Sir_Ahmed_ImranPaths (RMI21_paths)C++17
19 / 100
1095 ms7748 KiB
            //    01001100 01001111 01010100 01000001    \\
            //                                           \\
            //                ╦  ╔═╗╔╦╗╔═╗               \\
            //                ║  ║ ║ ║ ╠═╣               \\
            //                ╩═╝╚═╝ ╩ ╩ ╩               \\
            //                                           \\
            //    01001100 01001111 01010100 01000001    \\

#include <bits/stdc++.h>
using namespace std;
#define N 2001
#define nl '\n'
#define ff first
#define ss second
#define add insert
#define ll long long
#define ld long double
#define terminator main
#define pll pair<ll,ll>
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int n, k;
ll dp[N][N];
vector<pll> a[N];

void dfs(int v, int u){
    for(int i = 0; i <= k; i++)
        dp[v][i] = 0;
    for(auto & [i, j] : a[v]){
        if(i == u) continue;
        dfs(i, v);
        for(int x = k - 1; x >= 0; x--)
            for(int y = x + 1; y <= k; y++)
                dp[v][y] = max(dp[v][y], dp[v][x] + dp[i][y - x] + j);
    }
}

void solve(){
    int v, u, w;
    cin >> n >> k;
    for(int i = 1; i < n; i++){
        cin >> v >> u >> w;
        a[v].append({u, w});
        a[u].append({v, w});
    }
    for(int r = 1; r <= n; r++){
        dfs(r, 0);
        cout << dp[r][k] << nl;
    }
}
int terminator(){
    L0TA;
    solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...