题目大意:
有 n n n个点, m m m条边,问需要多少条边使得每个点的度大于 k k k
解题思路:
90
p
t
s
90pts
90pts用个小根堆,每次取最小连起来(
O
(
a
n
s
)
O(ans)
O(ans))比较容易被卡
100
p
t
s
100pts
100pts
统计出每个点所需要的度数
如果需要度数最多的点需要的度数大于其他点所需的度数那么直接输出这个点所需要的度数
否则输出所有点所需度数的总和整除二向上取整
A c c e p t e d c o d e Accepted\ code Accepted code
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
priority_queue <int> q;
int n, m, k, u, v, sum, ans;
int a[100005];
inline int read() {
int f = 0, flag = 1; char c = getchar();
while (isdigit(c) == 0) flag = (c == '-') ? -1 : 1, c = getchar();
while (isdigit(c) != 0) f = (f<<1) + (f<<3) + c - 48, c = getchar();
return flag * f;
}
signed main() {
n = read(), m = read(), k = read();
for (int i = 1; i <= m; ++i) ++a[read()], ++a[read()];
for (int i = 1; i <= n; ++i)
a[i] = max(k - a[i], 0ll);
long long maxn = -1e9;
for (int i = 1; i <= n; ++i) {
maxn = max(a[i], maxn);
ans += a[i];
}
if (maxn >= ans - maxn) printf("%lld", maxn);
else printf("%lld", (ans+1) >> 1);
return printf("\n") & 0;
}