Submission #1095001

# Submission time Handle Problem Language Result Execution time Memory
1095001 2024-10-01T07:05:14 Z blackslex Museum (CEOI17_museum) C++17
20 / 100
425 ms 1048576 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int n, k, c, x, y, z;

int main() {
    scanf("%d %d %d", &n, &k, &c);
    vector<int> sz(n + 5, 1);
    vector<vector<pii>> v(n + 5, vector<pii>());
    vector<vector<vector<ll>>> dp(n + 5, vector<vector<ll>>(2, vector<ll>(n + 5)));
    for (int i = 1; i < n; i++) {
        scanf("%d %d %d", &x, &y, &z);
        v[x].emplace_back(y, z); v[y].emplace_back(x, z);
    }
    function<void(int, int)> dfs = [&] (int cur, int par) {
        dp[cur][0] = dp[cur][1] = {0, 0};
        for (auto &[x, y]: v[cur]) {
            if (par == x) continue;
            dfs(x, cur);
            for (auto i: {0, 1}) {
                while (dp[cur][i].size() < sz[cur] + sz[x] + 1) dp[cur][i].emplace_back(1e18);
            }
            for (int i = sz[cur]; ~i; i--) {
                for (int j = sz[x]; ~j; j--) {
                    dp[cur][0][i + j] = min(dp[cur][0][i + j], dp[cur][1][i] + dp[x][0][j] + y);
                    dp[cur][0][i + j] = min(dp[cur][0][i + j], dp[cur][0][i] + dp[x][1][j] + y * 2);
                    dp[cur][1][i + j] = min(dp[cur][1][i + j], dp[cur][1][i] + dp[x][1][j] + y * 2);
                }
            }
            sz[cur] += sz[x];
        }
    };
    dfs(c, 0);
    printf("%lld", min(dp[c][0][k], dp[c][1][k]));
}

Compilation message

museum.cpp: In lambda function:
museum.cpp:24:42: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   24 |                 while (dp[cur][i].size() < sz[cur] + sz[x] + 1) dp[cur][i].emplace_back(1e18);
      |                        ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
museum.cpp: In function 'int main()':
museum.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d %d", &n, &k, &c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
museum.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%d %d %d", &x, &y, &z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 425 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 425 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Runtime error 425 ms 1048576 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -