| 比赛 |
2025.12.13 |
评测结果 |
AAWAWWWWWAWWWAAAAWAWWWWAWWWWWW |
| 题目名称 |
巡逻 |
最终得分 |
33 |
| 用户昵称 |
梦那边的美好CE |
运行时间 |
0.564 s |
| 代码语言 |
C++ |
内存使用 |
7.58 MiB |
| 提交时间 |
2025-12-13 08:58:03 |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dp[114514],n,k,u,v,ans;
vector<int>g[114514];
void DP(int x,int fa){
for(auto y:g[x]){
if(fa==y)continue;
DP(y,x);
ans=max(ans,dp[x]+dp[y]+1);
dp[x]=max(dp[x],dp[y]+1);
}
}
signed main(){
freopen("xunluo.in","r",stdin);freopen("xunluo.out","w",stdout);
ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>k;
for(int i=1;i<n;i++){
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
DP(1,0);
cout<<n+n-1-ans;
return 0;
}