当前位置:网站首页>G. Mountaineering Squad (violence & dfs)
G. Mountaineering Squad (violence & dfs)
2022-08-04 14:15:00 【Harris-H】
G.登山小分队(暴力&dfs)
开vectorMaintain the time of people reaching each vertex.每次排序,Update the same time and then merge up.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e5 + 5;
int n, u, v, x;
vector<int> vec[N], g[N];
void dfs(int x, int fa) {
int flag = 1;
for (auto y : vec[x]) {
if (y == fa)
continue;
dfs(y, x);
flag = 0;
}
if (flag) //叶
g[x].push_back(0);
sort(g[x].begin(), g[x].end());
if (x != 1) {
int len = g[x].size();
for (int i = 1; i < len; i++) //当前结点 The processing arrival time is the same
g[x][i] = max(g[x][i], g[x][i - 1] + 1);
for (auto v : g[x]) //+1Submit to parent node
g[fa].push_back(v + 1);
}
}
signed main() {
cin >> n;
for (int i = 1; i < n; i++) {
cin >> u >> v;
vec[u].push_back(v);
vec[v].push_back(u);
}
dfs(1, -1);
// for (int i = 1; i <= n; i++) {
// cout << i << ":" << endl;
// for (auto x : g[i])
// cout << x << " ";
// cout << endl;
// }
cout << g[1][g[1].size() - 1];
return 0;
}
边栏推荐
- CF1527D MEX Tree(mex&树&容斥)
- Chinese valentine's day, of course, to learn SQL optimization better leave work early to find objects
- odoo13 note point
- 文字编码 - Markdown 简明教程
- 智能电视可以打开小程序应用,再也不用头痛内存了
- Lecture 4 SVN
- VBS函数应用–getobject的使用获得Automation对象
- 人像分割技术解析与应用
- ACL 2022 | 社会科学理论驱动的言论建模
- Is there a replacement for the LM2596?LM2576 can
猜你喜欢
随机推荐
按键控制开关4017芯片数字电路
idea permanent activation tutorial (new version)
odoo13 note point
【硬件架构的艺术】学习笔记(1)亚稳态的世界
让Web页面中的编辑器支持黏贴或直接拖拽来添加图片「建议收藏」
AVR学习笔记之熔丝位
橄榄枝大课堂APP正式启动上线
如何确定异步 I/O 瓶颈
How to find the location of a pdf file in endnote literature
从理论到实践:MySQL性能优化和高可用架构,一次讲清
错误 AttributeError type object 'Callable' has no attribute '_abc_registry' 解决方案
Set partition minimum difference problem (01 knapsack)
centos7安装mysql急速版
四平方和,激光炸弹
记录都有哪些_js常用方法总结
The Internet of things application development trend
G.登山小分队(暴力&dfs)
Map常见的遍历方式-keySet 和 entrySet
2546 饭卡(01背包,挺好的)
世间几乎所有已知蛋白质结构,都被DeepMind开源了









