| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 951990 | vjudge1 | Museum (CEOI17_museum) | C++14 | 844 ms | 422180 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
struct edge{
int to,w;
};
int dp[N][N],son[N],f[N][N];
vector<edge>G[N];
int n,k,x;
inline void dfs(int u,int fa){
son[u]=1;
dp[u][0]=dp[u][1]=0;
for(auto v:G[u]){
if(v.to==fa) continue;
dfs(v.to,u);son[u]+=son[v.to];
for(int i=min(k,son[u]);i>=1;i--)
for(int j=min(i-1,son[v.to]);j>=1;j--){
if(dp[u][i]-f[u][i]>=dp[u][i-j]+dp[v.to][j]+v.w*2-max(f[u][i-j],f[v.to][j]+v.w)){
dp[u][i]=dp[u][i-j]+dp[v.to][j]+v.w*2;
f[u][i]=max(f[u][i-j],f[v.to][j]+v.w);
}
}
}
}
int main(){
memset(dp,0x3f,sizeof dp);
scanf("%d%d%d",&n,&k,&x);
for(int i=1;i<n;i++){
int u,v,w;scanf("%d%d%d",&u,&v,&w);
G[u].push_back({v,w});G[v].push_back({u,w});
}
dfs(x,0);
printf("%d",dp[x][k]-f[x][k]);
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
