B. Vasya and Isolated Vertices 模拟

Vasya has got an undirected graph consisting of n vertices and m edges. This graph doesn’t contain any self-loops or multiple edges. Self-loop is an edge connecting a vertex to itself. Multiple edges are a pair of edges such that they connect the same pair of vertices. Since the graph is undirected, the pair of edges (1,2) and (2,1)

is considered to be multiple edges. Isolated vertex of the graph is a vertex such that there is no edge connecting this vertex to any other vertex.

Vasya wants to know the minimum and maximum possible number of isolated vertices in an undirected graph consisting of n
vertices and m

edges.
Input

The only line contains two integers n
and m (1≤n≤105,0≤m≤n(n−1)2)

.

It is guaranteed that there exists a graph without any self-loops or multiple edges with such number of vertices and edges.
Output

In the only line print two numbers min
and max

— the minimum and maximum number of isolated vertices, respectively.
Examples
Input
Copy

4 2

Output
Copy

0 1

Input
Copy

3 1

Output
Copy

1 1

Note

In the first example it is possible to construct a graph with 0
isolated vertices: for example, it should contain edges (1,2) and (3,4). To get one isolated vertex, we may construct a graph with edges (1,2) and (1,3)

.

In the second example the graph will always contain exactly one isolated vertex.


给 n 个点,m 条边,问孤立点个数的max && min ;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 600005
#define inf 0x3f3f3f3f
#define INF 999999999999999
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const int mod = 10000007;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-7
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;

inline int rd() {
	int x = 0;
	char c = getchar();
	bool f = false;
	while (!isdigit(c)) {
		if (c == '-') f = true;
		c = getchar();
	}
	while (isdigit(c)) {
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return f ? -x : x;
}

ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }




int main()
{
	//ios::sync_with_stdio(false);
	ll n, m; rdllt(n); rdllt(m);
	cout << max(0ll, n - 2 * m) << ' ';
	int pos = 0;
	if (n == 1 && m == 0) {
		cout << 1 << endl;
	}
	else {
		for (ll i = 2; i <= n; i++) {
			if (m <= i * (i - 1) / 2 && m > (i - 1)*(i - 2) / 2) {
				pos = i; break;
			}
		}
		if (m == n * (n - 1) / 2)cout << 0 << endl;
		else {
			cout << n - pos << endl;
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40273481/article/details/83023552