Submission #537676

# Submission time Handle Problem Language Result Execution time Memory
537676 2022-03-15T11:15:15 Z siewjh Paths (RMI21_paths) C++17
36 / 100
204 ms 6432 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
typedef long long ll;
vector<pair<int, ll>> adjlist[1005];
ll dp[1005][105];
int nodes, choose;
int dfs(int x, int par){
    int leaf = 0;
    dp[x][0] = 0;
    for (auto nxt : adjlist[x]){
        int nn = nxt.first;
        if (nn == par) continue;
        leaf += dfs(nn, x);
    }
    for (auto nxt : adjlist[x]){
        int nn = nxt.first; ll nd = nxt.second;
        if (nn == par) continue;
        ll dph[1005];
        int mch = min(leaf, choose);
        for (int i = 0; i <= mch; i++) dph[i] = dp[x][i];
        for (int i = 1; i <= mch; i++){
            if (dp[nn][i] == -1) break;
            for (int j = i; j <= mch; j++){
                if (dp[x][j - i] == -1) break;
                dph[j] = max(dph[j], dp[nn][i] + dp[x][j - i] + nd);
            }
        }
        for (int i = 0; i <= mch; i++) dp[x][i] = dph[i];
    }
    if (leaf == 0) {
        leaf = 1;
        dp[x][1] = 0;
    }
    return leaf;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> nodes >> choose;
    for (int i = 1; i < nodes; i++){
        int a, b; ll c; cin >> a >> b >> c;
        adjlist[a].push_back({b, c});
        adjlist[b].push_back({a, c});
    }
    for (int i = 1; i <= nodes; i++){
        memset(dp, -1, sizeof(dp));
        dfs(i, -1);
        cout << dp[i][choose] << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 8 ms 1236 KB Output is correct
4 Correct 8 ms 1908 KB Output is correct
5 Correct 19 ms 1248 KB Output is correct
6 Correct 10 ms 1728 KB Output is correct
7 Correct 11 ms 1424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 8 ms 1236 KB Output is correct
4 Correct 8 ms 1908 KB Output is correct
5 Correct 19 ms 1248 KB Output is correct
6 Correct 10 ms 1728 KB Output is correct
7 Correct 11 ms 1424 KB Output is correct
8 Correct 180 ms 1424 KB Output is correct
9 Correct 204 ms 6432 KB Output is correct
10 Correct 95 ms 2772 KB Output is correct
11 Correct 170 ms 1300 KB Output is correct
12 Correct 104 ms 1996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 8 ms 1236 KB Output is correct
4 Correct 8 ms 1908 KB Output is correct
5 Correct 19 ms 1248 KB Output is correct
6 Correct 10 ms 1728 KB Output is correct
7 Correct 11 ms 1424 KB Output is correct
8 Correct 180 ms 1424 KB Output is correct
9 Correct 204 ms 6432 KB Output is correct
10 Correct 95 ms 2772 KB Output is correct
11 Correct 170 ms 1300 KB Output is correct
12 Correct 104 ms 1996 KB Output is correct
13 Runtime error 1 ms 468 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 8 ms 1236 KB Output is correct
4 Correct 8 ms 1908 KB Output is correct
5 Correct 19 ms 1248 KB Output is correct
6 Correct 10 ms 1728 KB Output is correct
7 Correct 11 ms 1424 KB Output is correct
8 Correct 180 ms 1424 KB Output is correct
9 Correct 204 ms 6432 KB Output is correct
10 Correct 95 ms 2772 KB Output is correct
11 Correct 170 ms 1300 KB Output is correct
12 Correct 104 ms 1996 KB Output is correct
13 Runtime error 1 ms 468 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -