Submission #537592

# Submission time Handle Problem Language Result Execution time Memory
537592 2022-03-15T09:25:54 Z joelau Paths (RMI21_paths) C++14
19 / 100
600 ms 18436 KB
#include <bits/stdc++.h>
using namespace std;
 
long long N,K, dp[2005][2005], num[2005], tmp[2005];
vector< pair<long long,long long> > lst[100005];
 
void dfs (long long x, long long p) {
    memset(dp[x],-1,sizeof(dp[x]));
    num[x] = 0, dp[x][0] = 0;
    for (auto v: lst[x]) if (v.first != p) {
        dfs(v.first,x);
        num[x] += num[v.first];
    }
    if (num[x] == 0) num[x] = 1, dp[x][1] = 0;
    for (auto v: lst[x]) if (v.first != p) {
        for (long long i = 0; i <= num[x] && i <= K; ++i) tmp[i] = dp[x][i];
        for (long long i = 1; i <= num[v.first] && i <= K && dp[v.first][i] != -1; ++i)
            for (long long j = 0; i+j <= num[x] && dp[x][j] != -1 && i+j <= K; ++j)
                tmp[i+j] = max(tmp[i+j],dp[v.first][i] + dp[x][j] + v.second);
        swap(tmp,dp[x]);
    }
}
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> K;
    for (long long i = 0; i < N-1; ++i) {
        long long u,v,w; cin >> u >> v >> w; u--, v--;
        lst[u].emplace_back(v,w), lst[v].emplace_back(u,w);
    }
    for (long long i = 0; i < N; ++i) {
        dfs(i,-1);
        cout << dp[i][K] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2900 KB Output is correct
2 Correct 2 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2900 KB Output is correct
2 Correct 2 ms 2900 KB Output is correct
3 Correct 78 ms 5844 KB Output is correct
4 Correct 99 ms 5844 KB Output is correct
5 Correct 90 ms 5844 KB Output is correct
6 Correct 85 ms 5964 KB Output is correct
7 Correct 79 ms 5844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2900 KB Output is correct
2 Correct 2 ms 2900 KB Output is correct
3 Correct 78 ms 5844 KB Output is correct
4 Correct 99 ms 5844 KB Output is correct
5 Correct 90 ms 5844 KB Output is correct
6 Correct 85 ms 5964 KB Output is correct
7 Correct 79 ms 5844 KB Output is correct
8 Execution timed out 1095 ms 18436 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2900 KB Output is correct
2 Correct 2 ms 2900 KB Output is correct
3 Correct 78 ms 5844 KB Output is correct
4 Correct 99 ms 5844 KB Output is correct
5 Correct 90 ms 5844 KB Output is correct
6 Correct 85 ms 5964 KB Output is correct
7 Correct 79 ms 5844 KB Output is correct
8 Execution timed out 1095 ms 18436 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 15692 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2900 KB Output is correct
2 Correct 2 ms 2900 KB Output is correct
3 Correct 78 ms 5844 KB Output is correct
4 Correct 99 ms 5844 KB Output is correct
5 Correct 90 ms 5844 KB Output is correct
6 Correct 85 ms 5964 KB Output is correct
7 Correct 79 ms 5844 KB Output is correct
8 Execution timed out 1095 ms 18436 KB Time limit exceeded
9 Halted 0 ms 0 KB -