2017 Multi-University Training Contest - Team 3 hdu6060 RXD and dividing
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6060
题目:
RXD and dividing
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 522 Accepted Submission(s): 219
Define f(S) as the the cost of the minimal Steiner Tree of the set S on tree T.
he wants to divide 2,3,4,5,6,…n into k parts S1,S2,S3,…Sk,
where ⋃Si={2,3,…,n} and for all different i,j , we can conclude that Si⋂Sj=∅.
Then he calulates res=∑ki=1f({1}⋃Si).
He wants to maximize the res.
1≤k≤n≤106
the cost of each edge∈[1,105]
Si might be empty.
f(S) means that you need to choose a couple of edges on the tree to make all the points in S connected, and you need to minimize the sum of the cost of these edges. f(S) is equal to the minimal cost
For each test case, the first line consists of 2 integer n,k, which means the number of the tree nodes , and k means the number of parts.
The next n−1 lines consists of 2 integers, a,b,c, means a tree edge (a,b) with cost c.
It is guaranteed that the edges would form a tree.
There are 4 big test cases and 50 small test cases.
small test case means n≤100.
1 2 3
2 3 4
2 4 5
2 5 6

#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; vector<PII>mp[K];
int n,k,sz[K];
LL ans;
void dfs(int u,int f)
{
sz[u]=;
for(auto v:mp[u])if(f!=v.first) dfs(v.first,u),sz[u]+=sz[v.first];
for(auto v:mp[u])if(f!=v.first) ans+=1LL*v.second*min(sz[v.first],k);
}
int main(void)
{ while(~scanf("%d%d",&n,&k))
{
ans=;
memset(mp,,sizeof mp);
for(int i=,x,y,z;i<n;i++)
scanf("%d%d%d",&x,&y,&z),mp[x].PB(MP(y,z)),mp[y].PB(MP(x,z));
dfs(,);
printf("%lld\n",ans);
}
return ;
}
2017 Multi-University Training Contest - Team 3 hdu6060 RXD and dividing的更多相关文章
- 2017 Multi-University Training Contest - Team 3——HDU6063 RXD and math
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6063 题目意思:字面意思,给出n,k,算出这个式子的答案. 思路:比赛的时候是打表找规律过了,赛后仔细 ...
- 【2017 Multi-University Training Contest - Team 3】RXD and math
[Link]: [Description] [Solution] 发现1010mod(109+7)=999999937; 猜测答案是nk 写个快速幂; 注意对底数先取模; [NumberOf WA] ...
- 【2017 Multi-University Training Contest - Team 3】RXD's date
[Link]: [Description] [Solution] [NumberOf WA] 1 [Reviw] [Code] #include <bits/stdc++.h> using ...
- 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】
FFF at Valentine Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】
Dying Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】
CSGO Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- 2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】
Ch’s gift Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- 2017 Multi-University Training Contest - Team 9 1001&&HDU 6161 Big binary tree【树形dp+hash】
Big binary tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】
Colorful Tree Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
随机推荐
- Spring配置文件总结
http://blog.csdn.net/zhejingyuan/article/details/41042789
- string类(二、常用string函数)
常用string相关,参至System.String类: 1/ string.Length a.Length字符串长度 string a="a5"; //a.Length==2 s ...
- Hibernate_day03--Hibernate多对多操作
Hibernate多对多操作 多对多映射配置 以用户和角色为例演示 第一步 创建实体类,用户和角色 第二步 让两个实体类之间互相表示 (1)一个用户里面表示所有角色,使用set集合 具体: User. ...
- ios开发之 -- UIView总结
如果想调用某个类的某个方法可以写成这样,这个方法来自NSObject类 performSelector: performSelector:withObject: performSelector:wit ...
- ionic触摸事件
官方文档:http://ionicframework.com/docs/api/directive/onHold/ on-hold 长按事件on-tap 点击事件 on-double-tap 双击事 ...
- Linux命令之乐--time
time用于统计命令执行花费的总时间 例一: [root@Director usr]# time ls bin etc games include java lib lib64 libexec loc ...
- Android下在onCreate中获取控件的宽度和高度(通过回调)
有时候需要在onCreate方法中知道某个View组件的宽度和高度等信息, 而直接调用View组件的getWidth().getHeight().getMeasuredWidth().getMeasu ...
- LeetCode-Add and Search Word
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- 桌面不显示IE图标解决方法
如果你的是WIN7,恰好你的桌面上IE图标不知道怎么被搞咩了. 向这里看过来,这里有一个文件你正好能用上. 使用方法很简单: 猛戳下载,猛戳两下安装 下载解决
- Groovy基本句法
Groovy基本句法 Gradle作为一个构建工具自然不会自己去创造一门语言来支撑自己,那么它用的是哪门子语言呢?什么语言能写成这样: task hello { doLast { println 'H ...