# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
951994 | vjudge1 | Museum (CEOI17_museum) | C++17 | 20 ms | 28508 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 MAXN=10005;
int n,m,x,son[MAXN],dp[MAXN][MAXN];
struct node{int to,cost;};
vector<node>g[MAXN];
void dfs(int u,int fa){
for(auto i:g[u]){
int v=i.to;
if(v==fa) continue;
dfs(v,u);son[u]+=son[v]+1;
for(int j=min(m-1,son[u]);j>=0;j--)
for(int k=min(j-1,son[v]);k>=0;k--)
dp[u][j]=max(dp[u][j],dp[u][j-k-1]+dp[v][k]+i.cost);
}
}
int main(){
scanf("%d%d%d",&n,&m,&x);
for(int i=1;i<=n-1;i++){
int u,v,c;scanf("%d%d%d",&u,&v,&c);
g[u].push_back({v,c});
g[v].push_back({u,c});
}
dfs(x,0);
printf("%d",dp[x][m-1]);
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... |