Submission #856461

# Submission time Handle Problem Language Result Execution time Memory
856461 2023-10-03T14:53:42 Z ttamx Museum (CEOI17_museum) C++14
100 / 100
417 ms 784976 KB
#include<bits/stdc++.h>

using namespace std;

const int N=10005;
const int inf=1e9;

int n,k,x;
vector<pair<int,int>> adj[N];
int dp[2][N][N];
int sz[N];

void dfs(int u,int p=-1){
    sz[u]=1;
    for(auto [v,w]:adj[u])if(v!=p){
        dfs(v,u);
        for(int i=sz[u];i>=0;i--){
            for(int j=sz[v];j>=0;j--){
                dp[0][u][i+j]=min(dp[0][u][i+j],dp[0][u][i]+dp[0][v][j]+w*2);
                dp[1][u][i+j]=min(dp[1][u][i+j],dp[1][u][i]+dp[0][v][j]+w*2);
                dp[1][u][i+j]=min(dp[1][u][i+j],dp[0][u][i]+dp[1][v][j]+w);
            }
        }
        sz[u]+=sz[v];
    }
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> k >> x;
    for(int i=1;i<n;i++){
        int u,v,w;
        cin >> u >> v >> w;
        adj[u].emplace_back(v,w);
        adj[v].emplace_back(u,w);
    }
    for(int i=1;i<=n;i++)for(int j=2;j<=n;j++)dp[0][i][j]=dp[1][i][j]=inf;
    dfs(x);
    cout << dp[1][x][k];
}

Compilation message

museum.cpp: In function 'void dfs(int, int)':
museum.cpp:15:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   15 |     for(auto [v,w]:adj[u])if(v!=p){
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 784620 KB Output is correct
2 Correct 241 ms 784468 KB Output is correct
3 Correct 293 ms 784820 KB Output is correct
4 Correct 263 ms 784716 KB Output is correct
5 Correct 268 ms 784464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 784620 KB Output is correct
2 Correct 241 ms 784468 KB Output is correct
3 Correct 293 ms 784820 KB Output is correct
4 Correct 263 ms 784716 KB Output is correct
5 Correct 268 ms 784464 KB Output is correct
6 Correct 271 ms 784588 KB Output is correct
7 Correct 313 ms 784720 KB Output is correct
8 Correct 417 ms 784584 KB Output is correct
9 Correct 350 ms 784620 KB Output is correct
10 Correct 269 ms 784468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6848 KB Output is correct
6 Correct 251 ms 784620 KB Output is correct
7 Correct 241 ms 784468 KB Output is correct
8 Correct 293 ms 784820 KB Output is correct
9 Correct 263 ms 784716 KB Output is correct
10 Correct 268 ms 784464 KB Output is correct
11 Correct 271 ms 784588 KB Output is correct
12 Correct 313 ms 784720 KB Output is correct
13 Correct 417 ms 784584 KB Output is correct
14 Correct 350 ms 784620 KB Output is correct
15 Correct 269 ms 784468 KB Output is correct
16 Correct 263 ms 784464 KB Output is correct
17 Correct 249 ms 784628 KB Output is correct
18 Correct 294 ms 784752 KB Output is correct
19 Correct 367 ms 784624 KB Output is correct
20 Correct 248 ms 784468 KB Output is correct
21 Correct 271 ms 784724 KB Output is correct
22 Correct 256 ms 784744 KB Output is correct
23 Correct 373 ms 784632 KB Output is correct
24 Correct 260 ms 784564 KB Output is correct
25 Correct 299 ms 784976 KB Output is correct