当前位置:网站首页>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;
}
边栏推荐
- Theory 1: Deep Learning - Detailed Explanation of the LetNet Model
- Is there a replacement for the LM2596?LM2576 can
- AutoCAD DWG,DXF文件导出高清图片、PDF
- Centos7 install mysql version rapidly
- idea去掉spark的日志
- 数据库恢复
- 让Web页面中的编辑器支持黏贴或直接拖拽来添加图片「建议收藏」
- odoo13 note point
- 理论篇1:深度学习之----LetNet模型详解
- How to find the location of a pdf file in endnote literature
猜你喜欢

Button control switch 4017 digital circuit chip

开放麒麟 openKylin 版本规划敲定:10 月发布 0.9 版并开启公测,12 月发布 1.0 版

Almost all known protein structures in the world are open sourced by DeepMind

数据库恢复

Lixia Action | Kyushu Yunzhang Jinnan: Open source is not a movement for a few people, popularization is the source

Theory 1: Deep Learning - Detailed Explanation of the LetNet Model

Unity插件:使用PopulationSystem制作行走交流的路人

《C 陷阱与缺陷 》阅读概要

谷歌插件.crx文件下载后被自动删除的解决方法

Qt的QItemDelegate使用
随机推荐
错误 AttributeError type object 'Callable' has no attribute '_abc_registry' 解决方案
【LeetCode】38、外观数列
国家安全机关对涉嫌危害国家安全犯罪嫌疑人杨智渊实施刑事拘传审查
SQL语句的写法:Update、Case、 Select 一起的用法
CCF GLCC officially opened | Kyushu Cloud open source experts bring generous bonuses to help universities promote open source
Theory 1: Deep Learning - Detailed Explanation of the LetNet Model
oracle+RAC+linux5.1所需要安装的包
How to Identify Asynchronous I/O Bottlenecks
word2003按空格键为什么会出现小数点
理论篇1:深度学习之----LetNet模型详解
【LeetCode】1403. 非递增顺序的最小子序列
metaRTC5.0新版本支持mbedtls(PolarSSL)
Problem solving-->Online OJ (18)
异步编程概览
人像分割技术解析与应用
C# winforms 输入颜色转换颜色名
《中国综合算力指数》《中国算力白皮书》《中国存力白皮书》《中国运力白皮书》在首届算力大会上重磅发出
Button control switch 4017 digital circuit chip
AlphaFold 如何实现 AI 在结构生物学中的全部潜力
PAT甲级:1040 Longest Symmetric String