当前位置:网站首页>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;
}
边栏推荐
- 自监督学习未来是掩码自编码器?KAIST最新《自监督学习掩码自编码器》研究进展
- 异步编程概览
- C# 复制列表
- Crawler - action chain, xpath, coding platform use
- nVisual secondary development - Chapter 2 nVisual API operation guide Swagger use
- leetcode 48. Rotate Image (Medium)
- 如何才能有效、高效阅读?猿辅导建议“因材因时施教”
- Win11快速助手在哪里?Win11打开快速助手的方法
- 编程思想_编程有必要给孩子学吗?
- How to Identify Asynchronous I/O Bottlenecks
猜你喜欢
如何才能有效、高效阅读?猿辅导建议“因材因时施教”
CCF GLCC officially opened | Kyushu Cloud open source experts bring generous bonuses to help universities promote open source
电子行业MES管理系统有哪些特殊功能
如何查找endnote文献中pdf文件的位置
Redis 复习计划 - Redis主从数据一致性和哨兵机制
【LeetCode】38、外观数列
企业应当实施的5个云安全管理策略
考研上岸又转行软件测试,从5k到13k完美逆袭,杭州校区小哥哥拒绝平庸终圆梦!
Lixia Action | Kyushu Yunzhang Jinnan: Open source is not a movement for a few people, popularization is the source
Crawler - basic use of selenium, no interface browser, other uses of selenium, cookies of selenium, crawler cases
随机推荐
CF1527D MEX Tree(mex&树&容斥)
Set partition minimum difference problem (01 knapsack)
Install mysql on k8s
BZOJ 1798 维护序列 (多校连萌,对线段树进行加乘混合操作)
电子行业MES管理系统有哪些特殊功能
自监督学习未来是掩码自编码器?KAIST最新《自监督学习掩码自编码器》研究进展
【HMS core】【Media】【视频编辑服务】 在线素材无法展示,一直Loading状态或是网络异常
php中的ceil和floo以及round函数「建议收藏」
谁说 Mysql 单表最大 2000 W ?我硬要塞它 1 个亿
职场漫谈:为什么越是内卷的行业越有人争着抢着往里冲?好奇怪的说...
Almost all known protein structures in the world are open sourced by DeepMind
解题-->在线OJ(十八)
Chinese valentine's day, of course, to learn SQL optimization better leave work early to find objects
oracle+RAC+linux5.1所需要安装的包
LM2596有没有可以替代的?LM2576可以
并发程序的隐藏杀手——假共享(False Sharing)
LCP 06. 拿硬币-遍历
数据库恢复
ssm学习心得(完结篇
State security organs conduct criminal arrest and summons review on Yang Zhiyuan, a suspect suspected of endangering national security