acgo题库
  • 首页
  • 题库
  • 学习
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情提交记录(0)
  • 题解

    用深搜

    userId_undefined

    复仇者_纳西妲厨一位

    秩序白银题解仙人时空双修者集训营话痨
    20阅读
    0回复
    1点赞
  • 树的直径题解

    #include<bits/stdc++.h> using namespace std; const int maxn=1e6+10; vector<int>adj[maxn]; int dp[maxn],dep[maxn]; void dfs(int cur,int fa){ dep[cur]=dp[cur]=1; int x=0,y=0; for(auto &nxt:adj[cur]){ if(nxt==fa) continue; dfs(nxt,cur); dep[cur]=max(dep[cur],dep[nxt]+1); dp[cur]=max(dp[cur],dp[nxt]); if(dep[nxt]>x){ y=x; x=dep[nxt]; }else if(dep[nxt]>y){ y=dep[nxt]; } } dp[cur]=max(dp[cur],x+y+1); } int main(){ int n; cin>>n; for(int i=1;i<=n;i++){ int u,v; cin>>u>>v; adj[u].push_back(v); adj[v].push_back(u); } dfs(1,0); cout<<dp[1]-1<<endl; }

    userId_undefined

    程某某

    小有名气倔强青铜时间刺客空间掌握者时空双修者枚举·枚举小能手
    13阅读
    0回复
    1点赞
  • 好可爱

    userId_undefined

    趣味でヒーーローをやっている者だ

    时空双修者出道萌新题解仙人秩序白银枚举·枚举小能手循环·循环打卡人
    5阅读
    0回复
    0点赞
暂无数据

提交答案之后,这里将显示提交结果~

首页