题目描述
求一个和一号点连边的数量恰好为 k 的最小生成树
Sol
直接做无从下手
考虑到如果与一号点相连的边的权值越大 , 我们在MST加边的时候就会加的越少
也就是说这是个单调函数!!
我们可以二分一个值给所有和1相连的边加上 (凸优化???)
这样就一定能考察到一个与一号点连边数为 k 的最小生成树
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
inline int read()
{
int x=0;char ch=getchar();int t=1;
for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') t=-1;
for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
return x*t;
}
typedef long long ll;
typedef double db;
const int N=5e3+