A. Party
1.P3478 [POI2008] STA-Station2.E1. Weights Division (easy version)3.P5007 DDOSvoid 的疑惑4.P2168 [NOI2015] 荷马史诗5.P8306 【模板】字典树6.P1481 魔族密码7.P3128 [USACO15DEC] Max Flow P8.P3258 [JLOI2014] 松鼠的新家9.P5536 【XR-3】核心城市10.P5836 [USACO19DEC] Milk Visits S11.P3384 【模板】重链剖分/树链剖分12.P3038 [USACO11DEC] Grass Planting G13.P4551 最长异或路径14.F. Alex's whims15.J. 上学16.Game on Tree17.E. We Need More Bosses
18.A. Party
19.D. Strong Vertices20.B. Omkar and Heavenly Tree21.B. Mahmoud and Ehab and the bipartiteness22.P8655 [蓝桥杯 2017 国 B] 发现环23.P10298 [CCC 2024 S4] Painting Roads24.F. Gardening Friends25.D. Playoff Tournament26.E. Lomsat gelral27.F. Minimum Maximum Distance28.D. Book of Evil29.P2195 HXY造公园30.P3304 [SDOI2013] 直径31.D. Sasha and a Walk in the City32.D. Vitaly and Cycle33.P10838 『FLA - I』庭中有奇树34.F - Perfect Matching on a Tree题解
1.多根树结构,但是将-1的点设为0的子节点,就变成了单根树
2.仔细读题!!!只要同一链上的就不能在一个组里
code
#include<bits/stdc++.h>
using namespace std;
int depth[2005]={0};
vector<int> G[2005];
void dfs(int now)
{
for(auto next:G[now])
{
depth[next]=depth[now]+1;
dfs(next);
}
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
if(x==-1) x++;
G[x].push_back(i);
}
dfs(0);
int ans=0;
for(int i=1;i<=n;i++) ans=max(ans,depth[i]);
cout<<ans;
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~