A9282 | Three Trees
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The first line contains three space-separated integers $n_{1}$ , $n_{2}$ , $n_{3}$ — the number of vertices in the first, second, and third trees, respectively. The following $n_{1}-1$ lines describe the first tree. Each of these lines describes an edge in the first tree and contains a pair of integers separated by a single space — the numeric labels of vertices connected by the edge. The following $n_{2}-1$ lines describe the second tree in the same fashion, and the $n_{3}-1$ lines after that similarly describe the third tree. The vertices in each tree are numbered with consecutive integers starting with $1$ .
The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.
- In subproblem E1 (11 points), the number of vertices in each tree will be between $1$ and $1000$ , inclusive.
- In subproblem E2 (13 points), the number of vertices in each tree will be between $1$ and $100000$ , inclusive.
The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows.
- In subproblem E1 (11 points), the number of vertices in each tree will be between $1$ and $1000$ , inclusive.
- In subproblem E2 (13 points), the number of vertices in each tree will be between $1$ and $100000$ , inclusive.
输入格式
Print a single integer number — the maximum possible sum of distances between all pairs of nodes in the united tree.
输出格式
Consider the first test case. There are two trees composed of two nodes, and one tree with three nodes. The maximum possible answer is obtained if the trees are connected in a single chain of 7 vertices.
In the second test case, a possible choice of new edges to obtain the maximum answer is the following:
- Connect node 3 from the first tree to node 1 from the second tree;
- Connect node 2 from the third tree to node 1 from the second tree.
In the second test case, a possible choice of new edges to obtain the maximum answer is the following:
- Connect node 3 from the first tree to node 1 from the second tree;
- Connect node 2 from the third tree to node 1 from the second tree.
输入输出样例
输入 #1
2 2 3 1 2 1 2 1 2 2 3
输出 #1
56
输入 #2
5 1 4 1 2 2 5 3 4 4 2 1 2 1 3 1 4
输出 #2
151
Consider the first test case. There are two trees composed of two nodes, and one tree with three nodes. The maximum possible answer is obtained if the trees are connected in a single chain of 7 vertices.
In the second test case, a possible choice of new edges to obtain the maximum answer is the following:
- Connect node 3 from the first tree to node 1 from the second tree;
- Connect node 2 from the third tree to node 1 from the second tree.
In the second test case, a possible choice of new edges to obtain the maximum answer is the following:
- Connect node 3 from the first tree to node 1 from the second tree;
- Connect node 2 from the third tree to node 1 from the second tree.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted