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/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
随机推荐
- UVA - 590Always on the run(递推)
题目:UVA - 590Always on the run(递推) 题目大意:有一个小偷如今在计划着逃跑的路线,可是又想省机票费. 他刚開始在城市1,必须K天都在这N个城市里跑来跑去.最后一天达到城市 ...
- 汉字的ascii
- report_timing_requirement
report_timing_requirement -ignored 会报告set_faults_paths,set_multi_path等
- linux中关闭程序或进程
- PatentTips - Transitioning between virtual machine monitor domains in a virtual machine environment
BACKGROUND The present disclosure relates generally to microprocessor systems, and more specifically ...
- [Angular] Change component default template (ng-content, ng-template, ngTemplateOutlet, TemplateRef)
Here is the defulat tab header template: <ng-template #defaultTabHeader let-tabs="tabsX" ...
- php课程 8-29 gd库能够画哪些东西
php课程 8-29 gd库能够画哪些东西 一.总结 一句话总结:文字,点,线,圆,弧线,矩形,各种形状都是可以的,和html5中的canva能画的东西很像,使用也很像,参数怎么记呢,参数完全不用记, ...
- 【u123】最大子段和
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 给出一段序列,选出其中连续且非空的一段使得这段和最大. [输入格式] 输入文件maxsum1.in的第 ...
- [D3] Load and Inspect Data with D3 v4
You probably use a framework or standalone library to load data into your apps, but what if that’s o ...
- Linux上安装JDK 分类: B1_JAVA B3_LINUX 2014-08-29 15:12 449人阅读 评论(0) 收藏
1.下载rpm文件并安装 rpm -ivh jdk-7u51-linux-x64.rpm 2.修改/etc/profile文件,增加以下配置 export JAVA_HOME=/usr/java/jd ...