当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

量化细胞内的信息流:机器学习时代下的研究进展

Button control switch 4017 digital circuit chip

Phasecraft连下两城,助力英国量子技术商业化加速!

State security organs conduct criminal arrest and summons review on Yang Zhiyuan, a suspect suspected of endangering national security

metaRTC5.0新版本支持mbedtls(PolarSSL)

企业应当实施的5个云安全管理策略

按键控制开关4017芯片数字电路

Win11快速助手在哪里?Win11打开快速助手的方法

Crawler - basic use of selenium, no interface browser, other uses of selenium, cookies of selenium, crawler cases

CCF GLCC officially opened | Kyushu Cloud open source experts bring generous bonuses to help universities promote open source
随机推荐
字符串类的设计与实现_C语言字符串编程题
Keycloak 6.0.0 正式发布,身份和访问管理系统
文字编码 - XML 教程
如何通过使用“缓存”相关技术,解决“高并发”的业务场景案例?
九州云出席领航者线上论坛,共话5G MEC边缘计算现状、挑战和未来
数据库恢复
Phasecraft连下两城,助力英国量子技术商业化加速!
ACL 2022 | 社会科学理论驱动的言论建模
C# winforms 输入颜色转换颜色名
相似文本聚类与调参
异步编程概览
idea永久激活教程(新版)
metaRTC5.0新版本支持mbedtls(PolarSSL)
【硬件架构的艺术】学习笔记(1)亚稳态的世界
Redis 复习计划 - Redis主从数据一致性和哨兵机制
【HMS core】【Media】【视频编辑服务】 在线素材无法展示,一直Loading状态或是网络异常
AutoCAD DWG,DXF文件导出高清图片、PDF
烂大街的缓存穿透、缓存击穿和缓存雪崩,你真的懂了?
卷积神经网络 基础
Convolutional Neural Network Basics