답안 #988745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988745 2024-05-25T21:42:07 Z noyancanturk Museum (CEOI17_museum) C++17
20 / 100
13 ms 4700 KB
#include "bits/stdc++.h"
using namespace std;
    
#define int int64_t
#define pb push_back
    
const int lim=5100;
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 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3364 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3364 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Runtime error 13 ms 860 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -