답안 #537665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537665 2022-03-15T11:07:14 Z siewjh Paths (RMI21_paths) C++17
19 / 100
600 ms 8972 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
typedef long long ll;
vector<pair<int, ll>> adjlist[MAXN];
ll dp[MAXN][MAXN];
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];
        for (int i = 0; i < 1005; i++) dph[i] = dp[x][i];
        for (int i = 1; i <= min(leaf, choose); i++)
            for (int j = i; j <= min(leaf, choose); j++)
                dph[j] = max(dph[j], dp[nn][i] + dp[x][j - i] + nd);
        for (int i = 0; i < 1005; 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8316 KB Output is correct
2 Correct 15 ms 8308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8316 KB Output is correct
2 Correct 15 ms 8308 KB Output is correct
3 Correct 170 ms 8364 KB Output is correct
4 Correct 175 ms 8972 KB Output is correct
5 Correct 145 ms 8332 KB Output is correct
6 Correct 213 ms 8776 KB Output is correct
7 Correct 158 ms 8492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8316 KB Output is correct
2 Correct 15 ms 8308 KB Output is correct
3 Correct 170 ms 8364 KB Output is correct
4 Correct 175 ms 8972 KB Output is correct
5 Correct 145 ms 8332 KB Output is correct
6 Correct 213 ms 8776 KB Output is correct
7 Correct 158 ms 8492 KB Output is correct
8 Execution timed out 1095 ms 8440 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8316 KB Output is correct
2 Correct 15 ms 8308 KB Output is correct
3 Correct 170 ms 8364 KB Output is correct
4 Correct 175 ms 8972 KB Output is correct
5 Correct 145 ms 8332 KB Output is correct
6 Correct 213 ms 8776 KB Output is correct
7 Correct 158 ms 8492 KB Output is correct
8 Execution timed out 1095 ms 8440 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 496 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8316 KB Output is correct
2 Correct 15 ms 8308 KB Output is correct
3 Correct 170 ms 8364 KB Output is correct
4 Correct 175 ms 8972 KB Output is correct
5 Correct 145 ms 8332 KB Output is correct
6 Correct 213 ms 8776 KB Output is correct
7 Correct 158 ms 8492 KB Output is correct
8 Execution timed out 1095 ms 8440 KB Time limit exceeded
9 Halted 0 ms 0 KB -