本文网址:https://blog.csdn.net/xiaomaolin2/article/details/103496715
传送门:https://nanti.jisuanke.com/t/42580
首先这是个图论题,但是完全可以不用图论算法做,用简单的分析加上贪心即可 。
题意:N个点、M条带权边,其中有一部分(c == 1)为白边,一部分为(c == 0)为黑边,问在限制选择白边的最大数量为k的前 提下能不能完全连接这N个点,能连接时的最大被选中边权和为多少。
解题思路:黑边全选了,看有多少点没有被连接,然后在能到未连接点的白边中选择最长的。
具体实现,先上代码:
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <vector> #include <cstdio> #include <queue> #include <cmath> #include <map> #include <set> using namespace std; typedef long long ll; const int maxn=5e5+10; set<int>ss; int T; int n,m,k; struct edge{ int l; int r; int len; int flag; }edge[maxn]; int cmp(struct edge a,struct edge b){ return a.len >

这是一道2019年ICPC亚洲南昌区域赛的题目,主要考察图论和贪心算法。在限制选择白边不超过k的情况下,需要判断能否通过黑边和白边连接所有点,并求最大权值。解题策略是首先选取所有黑边,然后从能到达未连接点的白边中选取最长的。已提供代码实现和联系方式供讨论。
最低0.47元/天 解锁文章
331

被折叠的 条评论
为什么被折叠?



