CF1065B Vasya and Isolated Vertices 題解
阿新 • • 發佈:2021-09-13
CF1065B Vasya and Isolated Vertices 題解
題目分析
看著構造的標籤進來的,進來前沒想到這麼簡單
首先保留節點的最小值,就是讓每一條邊連線當前度數為 0 的兩個點,這樣子可以最大程度地利用每一條邊。
所以 \(\min=\max(0,n-2*m)\)
那麼保留節點的最大值,也就等價於最少的點連最多的邊,很容易想到完全圖,也就是點數為 \(n\) 的簡單圖 \(G\) ,最多有 \(\frac{n*(n-1)}{2}\) 條邊。
二分出邊數 \(\geq m\) ,點數最小且為 \(t\) 的完全圖,
則 \(\max=n-t\)
Code:
#include<bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x){ x=0;char ch=getchar();bool f=false; while(!isdigit(ch)) f|=ch=='-',ch=getchar(); while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); x=f?-x:x;return; } template <typename T> inline void print(T x){ if(x<0) putchar('-'),x=-x; if(x>9) print(x/10); putchar(x%10^48);return; } #define ll long long ll n,m; int main(){ read(n),read(m);ll minn=0,maxn=0; minn=max(0ll,n-2*m);print(minn),putchar(' '); ll l=0,r=n; while(l<=r){ ll mid=(l+r)>>1; if(mid*(mid-1)/2>=m) r=mid-1,maxn=mid; else l=mid+1; } print(n-maxn); return 0; }