欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1528A.Parsa's Humongous Tree
Parsa's Humongous Tree
CF1528A · Parsa's Humongous Tree
- 难度:1600
- 标签:dfs and similar、divide and conquer、dp、greedy、trees
- 链接:https://codeforces.com/problemset/problem/1528/A
- 时间限制:1 second 内存限制:256 megabytes
- 出现位置:Day17-树形DP-区间DP-计数DP
英文原题面
Statement
Parsa has a humongous tree on vertices. On each vertex he has written two integers and . To make Parsa's tree look even more majestic, Nima wants to assign a number () to each vertex such that the beauty of Parsa's tree is maximized. Nima's sense of the beauty is rather bizarre. He defines the beauty of the tree as the sum of over all edges of the tree. Since Parsa's tree is too large, Nima can't maximize its beauty on his own. Your task is to find the maximum possible beauty for Parsa's tree.
Input
The first line contains an integer — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer — the number of vertices in Parsa's tree. The -th of the following lines contains two integers and . Each of the next lines contains two integers and meaning that there is an edge between the vertices and in Parsa's tree. It is guaranteed that the given graph is a tree. It is guaranteed that the sum of over all test cases doesn't exceed .
Output
For each test case print the maximum possible beauty for Parsa's tree.
样例
样例 1
输入:
3
2
1 6
3 8
1 2
3
1 3
4 6
7 9
1 2
2 3
6
3 14
12 20
12 19
2 12
10 17
3 17
3 2
6 5
1 5
2 6
4 6
输出:
7
8
62
样例解释(英文原文)
The trees in the example:
In the first test case, one possible assignment is which results in . In the second test case, one of the possible assignments is which results in a beauty of
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |