# 重建道路

```#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#define rep(i,a,n) for(int i = a;i <= n;i++)
#define per(i,n,a) for(int i = n;i >= a;i--)
#define enter putchar(‘\n‘)

using namespace std;
typedef long long ll;
const int M = 10005;
const int INF = 1000000009;

{
int ans = 0,op = 1;
char ch = getchar();
while(ch < ‘0‘ || ch > ‘9‘)
{
if(ch == ‘-‘) op = -1;
ch = getchar();
}
while(ch >= ‘0‘ && ch <= ‘9‘)
{
ans *= 10;
ans += ch - ‘0‘;
ch = getchar();
}
return ans * op;
}

struct edge
{
int next,to,v;
}e[10005];

{
e[++ecnt].to = y;
}

void dfs(int x,int fa)
{
sum[x] = 1;
bool flag = 1;
for(int i = head[x];i;i = e[i].next)
{
int k = e[i].to;
if(k == fa) continue;
flag = 0;
dfs(k,x);
sum[x] += sum[k];
per(j,sum[x],0)
rep(p,1,j-1) dp[x][j] = min(dp[x][j],dp[x][j-p] + dp[k][p] - 1);
}
if(flag)
{
dp[x][1] = 0;
sum[x] = 1;
return;
}
}

int main()
{
memset(dp,127/3,sizeof(dp));
rep(i,1,n) dp[i][1] = son[i];
dfs(1,0);
int ans = dp[1][p];
rep(i,2,n) ans = min(ans,dp[i][p] + 1);
printf("%d\n",ans);
return 0;
}```

(0)
(0)

0条