답안 #988747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988747 2024-05-25T21:43:04 Z noyancanturk Museum (CEOI17_museum) C++17
20 / 100
712 ms 1048576 KB
#include "bits/stdc++.h"
using namespace std;
    
#define int int64_t
#define pb push_back
    
const int lim=10100;
const int mod=1e9+7;
    
using pii=pair<int,int>;

vector<pii>v[lim];
int sz[lim];
int dp[2][lim][lim];
void dfs(int node,int par){
    sz[node]=1;
    for(int i=0;i<lim;i++){
        dp[0][node][i]=dp[1][node][i]=INT_MAX;
    }
    dp[0][node][1]=dp[1][node][1]=0;
    for(auto[child,c]:v[node]){
        if(child==par)continue;
        dfs(child,node);
        for(int i=sz[node];i;i--){
            for(int j=1;j<=sz[child];j++){
                dp[0][node][i+j]=min(dp[0][node][i+j],dp[0][node][i]+dp[0][child][j]+2*c);
                dp[1][node][i+j]=min(
                    {
                        dp[1][node][i+j],
                        dp[0][node][i]+dp[1][child][j]+c,
                        dp[1][node][i]+dp[0][child][j]+2*c
                    }
                );
            }
        }
        sz[node]+=sz[child];
    }
}

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local  
    freopen(".in","r",stdin);freopen(".out","w",stdout);
#endif
    int n,k,x;
    cin>>n>>k>>x;
    for(int i=0;i<n-1;i++){
        int X,Y,Z;
        cin>>X>>Y>>Z;
        v[X].pb({Y,Z});
        v[Y].pb({X,Z});
    }
    dfs(x,0);
    cout<<dp[1][x][k]<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4240 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 712 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 712 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4240 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4440 KB Output is correct
6 Runtime error 712 ms 1048576 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -