답안 #922333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922333 2024-02-05T12:17:39 Z phong Museum (CEOI17_museum) C++17
0 / 100
320 ms 1048580 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

#define ll long long
const int nmax = 1e4 + 5;
const ll oo = 1e18, base = 311;
const int lg = 19, M = 10;
const ll mod = 1e9 + 7;
#define pii pair<ll, int>
#define fi first
#define se second
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' ';
using namespace std;

ll n, k, x;
ll a[nmax];

vector<pii> adj[nmax];
ll sz[nmax], f[nmax][nmax][2], tmp[nmax][2];
void ckmin(ll &a, ll b){
    a = min(a, b);
}
void dfs(int u, int p){
    sz[u] = 1;
    f[u][1][0] = a[u] * 2;
    f[u][1][1] = a[u];
    for(auto [w, v] : adj[u]){
        if(v == p) continue;
        a[v] = w;
        dfs(v, u);
        for(int i = 0; i <= sz[u]; ++i){
            tmp[i][0] = f[u][i][0];
            tmp[i][1] = f[u][i][1];
        }
        for(int x = 0; x <= sz[u]; ++x){
            for(int y = 0; y <= sz[v]; ++y){
                if(x + y > k) continue;
                ckmin(f[u][x + y][0], tmp[x][0] + f[v][y][0]);
                ckmin(f[u][x + y][1], tmp[x][0] + f[v][y][1] - a[u]);
                ckmin(f[u][x + y][1], tmp[x][1] + f[v][y][0]);
            }
        }
        sz[u] += sz[v];
    }
}
void update(){
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen("code.inp", "r", stdin);
//    freopen("code.ans", "w", stdout);
    cin >> n >> k >> x;
//    k = n - k;
    for(int i = 1, u, v, w; i < n; ++i){
        cin >> u >> v >> w;
        adj[u].push_back({w, v});
        adj[v].push_back({w, u});
    }
    memset(f, 0x3f, sizeof f);
    dfs(x, -1);
    cout << f[x][k][1];
}
/*
5 3 2
2 3 3
3 5 5
5 1 6
5 4 3


*/

Compilation message

museum.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 320 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 217 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 217 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 320 ms 1048580 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -