NOIP模拟 wall - 最大生成树
题目大意:
给出n个点,第i个点坐标是(\(x_i, y_i\)),给出m条边,第i条边的权值是\(w_i\),求将图变成一颗树所需要删除边的最小权值和。
题目分析:
首先要看出坐标其实是出题人使出的障眼法,把人往计算几何引。看透问题后就知道这是求一颗最大生成树。
code:
#include<bits/stdc++.h>
using namespace std;
const int N = 100005, M = 200005;
int n, m, T;
struct node{
int a, b, c;
inline bool operator < (const node &b) const{
return c > b.c;
}
};
vector<node> edges;
int anc[N];
typedef long long ll;
ll ans1, ans2;
inline int getAnc(int x){return x == anc[x] ? x : (anc[x] = getAnc(anc[x]));}
int main(){
freopen("h.in", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> T;
while(T--){
cin >> n >> m;
edges.clear(); ans1 = 0, ans2 = m;
for(int i = 1; i <= n; i++) anc[i] = i;
for(int i = 1; i <= n; i++){int x, y; cin >> x >> y;}
for(int i = 1; i <= m; i++){
int x, y, w; cin >> x >> y >> w;
edges.push_back((node){x, y, w});
ans1 += 1ll*w;
}
sort(edges.begin(), edges.end());
for(int i = 0; i < edges.size(); i++){
int f1 = getAnc(edges[i].a), f2 = getAnc(edges[i].b);
if(f1 != f2){anc[f1] = f2, ans1 -= 1ll*edges[i].c, ans2--;}
}
cout << ans2 << " " << ans1 << endl;
}
return 0;
}
NOIP模拟 wall - 最大生成树的更多相关文章
- 2018.08.30 NOIP模拟 wall(模拟)
[问题描述] 万里长城是中国强大的标志,长城在古代的用途主要用于快速传递军事消息和抵御 外敌,在长城上的烽火台即可以作为藏兵的堡垒有可以来点燃狼烟传递消息. 现在有一段 万里长城,一共有 N 个烽火台 ...
- CH Round #52 - Thinking Bear #1 (NOIP模拟赛)
A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...
- CH Round #55 - Streaming #6 (NOIP模拟赛day2)
A.九九归一 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2355%20-%20Streaming%20%236%20(NOIP模拟赛day2)/九九归一 题 ...
- 2021.9.17考试总结[NOIP模拟55]
有的考试表面上自称NOIP模拟,背地里却是绍兴一中NOI模拟 吓得我直接文件打错 T1 Skip 设状态$f_i$为最后一次选$i$在$i$时的最优解.有$f_i=max_{j<i}[f_j+a ...
- NOIP模拟赛20161022
NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
随机推荐
- JS contcat() 连接数组 函数
语法: arrayObject.concat(arrayX,arrayX,......,arrayX) 1.把元素添加到数组中 arr.concat(a,b,c);2.把数组连起来 arr.conca ...
- 【CS Round #46 (Div. 1.5) C】Set Subtraction
[链接]h在这里写链接 [题意] 一开始有n个数字,然后有一个数字X,把每个数字都减去X,又生成N个新的数字. 然后把这2*N个数字混在一起. 告诉你这2*N个数字是什么.让你复原出原来的N个数字,以 ...
- HorizontalListView中使用notifyDataSetChanged()和notifyDataSetInvalidated()
今天在项目中用到了水平ListView控件HorizontalListView,也是我在网上找的个开源HorizontalListView直接在项目中使用.我是把HorizontalListView放 ...
- Git 经常使用命令
Git经常使用命令备忘: Git配置 git config --global user.name "storm" git config --global user.email &q ...
- GCJ 2009 Round 2 Problem A. Crazy Rows
https://code.google.com/codejam/contest/204113/dashboard 题目大意: 给你一个矩阵,让你转化为下三角矩阵,每次只能交换相邻的行,求最小的交换次数 ...
- BaaS简介
SaaS(软件即服务:Software as a Service).IaaS(基础设施即服务:Infrastructure as a Service)和PaaS(平台即服务:Platform as a ...
- [Angular] Configurable Angular Components - Content Projection and Input Templates
We are going to have a modal component: <au-modal > </au-modal> And we can pass default ...
- [Angular] Angular Advanced Features - ng-template , ng-container, ngTemplateOutlet
Previously we have tab-panel template defined like this: <ul class="tab-panel-buttons" ...
- Summary Day30
1.内存管理 1.1 进程中的内存区域划分 代码区 仅仅读常理区 全局区 BSS 堆 栈 1.2 字符串存储形式之间的比較 字符指针,字符数组.字符动态内存 1.3 虚拟内 ...
- Android应用性能优化系列视图篇——隐藏在资源图片中的内存杀手
图片加载性能优化永远是Android领域中一个无法绕过的话题,经过数年的发展,涌现了很多成熟的图片加载开源库,比如Fresco.Picasso.UIL等等,使得图片加载不再是一个头疼的问题,并且大幅降 ...