前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDU - 6187 (最大生成树) 最小生成树

HDU - 6187 (最大生成树) 最小生成树

作者头像
风骨散人Chiam
发布2020-10-28 11:07:48
7170
发布2020-10-28 11:07:48
举报
文章被收录于专栏:CSDN旧文

Destroy Walls

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total Submission(s): 1774    Accepted Submission(s): 689

Problem Description

Long times ago, there are beautiful historic walls in the city. These walls divide the city into many parts of area. Since it was not convenient, the new king wants to destroy some of these walls, so he can arrive anywhere from his castle. We assume that his castle locates at (0.6∗2√,0.6∗3√). There are n towers in the city, which numbered from 1 to n. The ith's location is (xi,yi). Also, there are m walls connecting the towers. Specifically, the ith wall connects the tower ui and the tower vi(including the endpoint). The cost of destroying the ith wall is wi. Now the king asks you to help him to divide the city. Firstly, the king wants to destroy as less walls as possible, and in addition, he wants to make the cost least. The walls only intersect at the endpoint. It is guaranteed that no walls connects the same tower and no 2 walls connects the same pair of towers. Thait is to say, the given graph formed by the walls and towers doesn't contain any multiple edges or self-loops. Initially, you should tell the king how many walls he should destroy at least to achieve his goal, and the minimal cost under this condition.

Input

There are several test cases. For each test case: The first line contains 2 integer n, m. Then next n lines describe the coordinates of the points. Each line contains 2 integers xi,yi. Then m lines follow, the ith line contains 3 integers ui,vi,wi |xi|,|yi|≤105 3≤n≤100000,1≤m≤200000 1≤ui,vi≤n,ui≠vi,0≤wi≤10000

Output

For each test case outout one line with 2 integers sperate by a space, indicate how many walls the king should destroy at least to achieve his goal, and the minimal cost under this condition.

Sample Input

代码语言:javascript
复制

4 4 -1 -1 -1 1 1 1 1 -1 1 2 1 2 3 2 3 4 1 4 1 2

Sample Output

代码语言:javascript
复制

1 1

 只能说读题很难,我太难了。我给大家画个图解释一下样例。

这个国王被围起来,他要访问它所有的城市,必然要拆遍,不然出不去,就是说拆掉多少遍,使图成为联通的,也就是说不会保留环即可,无论这个国王在哪,这个图只要有环,就不能遍历,所以跟每个点的坐标没有任何关系,直接剔除环中的最小边,但是这样对吗?我们要使剃边花费最小,那么就要使剃边后剩下的无向无环图的边权和最最大,因为剔除环中最小边,不能保证提出的和最小,所以一遍最大生成树。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Destroy Walls
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档