A12763 | Fedor Runs for President
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Fedor runs for president of Byteland! In the debates, he will be asked how to solve Byteland's transport problem. It's a really hard problem because of Byteland's transport system is now a tree (connected graph without cycles). Fedor's team has found out in the ministry of transport of Byteland that there is money in the budget only for one additional road. In the debates, he is going to say that he will build this road as a way to maximize the number of distinct simple paths in the country. A simple path is a path which goes through every vertex no more than once. Two simple paths are named distinct if sets of their edges are distinct.
But Byteland's science is deteriorated, so Fedor's team hasn't succeeded to find any scientists to answer how many distinct simple paths they can achieve after adding exactly one edge on the transport system?
Help Fedor to solve it.
An edge can be added between vertices that are already connected, but it can't be a loop.
In this problem, we consider only simple paths of length at least two.
But Byteland's science is deteriorated, so Fedor's team hasn't succeeded to find any scientists to answer how many distinct simple paths they can achieve after adding exactly one edge on the transport system?
Help Fedor to solve it.
An edge can be added between vertices that are already connected, but it can't be a loop.
In this problem, we consider only simple paths of length at least two.
输入格式
The first line contains one integer $n$ ( $2 \leq n \leq 500\ 000$ ) — number of vertices in Byteland's transport system.
Each of the following $n - 1$ lines contains two integers $v_i$ and $u_i$ ( $1 \leq v_i, u_i \leq n$ ). It's guaranteed that the graph is tree.
Each of the following $n - 1$ lines contains two integers $v_i$ and $u_i$ ( $1 \leq v_i, u_i \leq n$ ). It's guaranteed that the graph is tree.
输出格式
Print exactly one integer — a maximal number of simple paths that can be achieved after adding one edge.
输入输出样例
输入 #1
2 1 2
输出 #1
2
输入 #2
4 1 2 1 3 1 4
输出 #2
11
输入 #3
6 1 2 1 3 3 4 3 5 4 6
输出 #3
29
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted