# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1106340 |
2024-10-30T02:59:33 Z |
whoknow |
Museum (CEOI17_museum) |
C++17 |
|
56 ms |
3912 KB |
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define MAXN 10005
#define ii pair<int,int>
#define bit(i,j) ((i>>j)&1)
#define sz(i) (int)i.size()
#define endl '\n'
using namespace std;
const int INF = 1e9;
int n, k, st;
vector<ii>g[MAXN];
namespace sub1
{
int res=INF;
int s[MAXN];
vector<ii> dp[MAXN];
vector<ii> combine(vector<ii>x, vector<ii>y)
{
vector<ii>ans(sz(x) + sz(y) - 1, {INF,INF});
ans[0]=x[0];
ans[1]=x[1];
for(int i = 1; i < sz(x); i++)
for(int j = 0; j <= min(sz(y) - 1, n - i); j++)
ans[i + j] =min(ans[i+j], {x[i].F + y[j].F,y[j].S});
return ans;
}
void dfs(int u, int p, int w)
{
s[u]=s[p]+w;
dp[u] = {{0,0}, {w,s[u]}};
for(ii i : g[u])
{
int v = i.F, w = i.S;
if(v == p)
continue;
dfs(v, u, w);
dp[u] = combine(dp[u], dp[v]);
}
}
void solve()
{
dfs(st, 0, 0);
cout<<dp[st][k].F*2-dp[st][k].S;
}
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k >> st;
for(int i = 1; i < n; i++)
{
int x, y, z;
cin >> x >> y >> z;
g[x].push_back({y, z});
g[y].push_back({x, z});
}
sub1::solve();
}
Compilation message
museum.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
48 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
3912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
3912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |