답안 #537578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537578 2022-03-15T08:53:22 Z joelau Paths (RMI21_paths) C++14
8 / 100
57 ms 15552 KB
#include <bits/stdc++.h>
using namespace std;

long long N,K, dp[1005][105], num[1005];
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) {
        long long tmp[105];
        for (long long i = 0; i <= num[x]; ++i) tmp[i] = dp[x][i];
        for (long long i = 1; i <= num[v.first] && dp[v.first][i] != -1; ++i)
            for (long long j = 0; i+j <= num[x] && dp[x][j] != -1; ++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';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 11 ms 2868 KB Output is correct
4 Correct 13 ms 2936 KB Output is correct
5 Runtime error 4 ms 5588 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 11 ms 2868 KB Output is correct
4 Correct 13 ms 2936 KB Output is correct
5 Runtime error 4 ms 5588 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 11 ms 2868 KB Output is correct
4 Correct 13 ms 2936 KB Output is correct
5 Runtime error 4 ms 5588 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 57 ms 15552 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 11 ms 2868 KB Output is correct
4 Correct 13 ms 2936 KB Output is correct
5 Runtime error 4 ms 5588 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -