当前位置:网站首页>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;
}
边栏推荐
- AVR学习笔记之熔丝位
- 人像分割技术解析与应用
- centos7安装mysql急速版
- Crawler - basic use of selenium, no interface browser, other uses of selenium, cookies of selenium, crawler cases
- 干掉visio,这个画图神器真的绝了
- 按键控制开关4017芯片数字电路
- 博途200/1500PLC多段曲线控温FB(支持40段控温曲线、段曲线搜索、暂停、跳段等功能)
- B.构造一个简单的数列(贪心)
- 将 Sentinel 熔断限流规则持久化到 Nacos 配置中心
- word2003按空格键为什么会出现小数点
猜你喜欢
随机推荐
token 过期后,如何自动续期?
卷积神经网络 基础
Set partition minimum difference problem (01 knapsack)
文盘Rust -- 配置文件解析
谷歌插件.crx文件下载后被自动删除的解决方法
AVR学习笔记之熔丝位
PAT甲级:1040 Longest Symmetric String
量化细胞内的信息流:机器学习时代下的研究进展
Unity插件:使用PopulationSystem制作行走交流的路人
php中的ceil和floo以及round函数「建议收藏」
2042. 检查句子中的数字是否递增-力扣双百代码-设置前置数据
世间几乎所有已知蛋白质结构,都被DeepMind开源了
Is there a replacement for the LM2596?LM2576 can
C# winforms 输入颜色转换颜色名
Qt的QItemDelegate使用
信创是什么意思?涉及哪些行业?为什么要发展信创?
如何查找endnote文献中pdf文件的位置
ICML 2022 | 图神经网络的局部增强
【无标题】
MySQL【触发器】