Educational Codeforces Round 52 (Rated for Div. 2)B. Vasya and Isolated Vertices·「模拟,思维」

B. Vasya and Isolated Vertices

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya has got an undirected graph consisting of nn vertices and mm 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)(1,2) and (2,1)(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 nn vertices and mm edges.

Input

The only line contains two integers nn and m (1≤n≤105,0≤m≤n(n−1)2)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 minmin and maxmax — 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 00 isolated vertices: for example, it should contain edges (1,2)(1,2) and (3,4)(3,4). To get one isolated vertex, we may construct a graph with edges (1,2)(1,2) and (1,3)(1,3).

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

题目大意:给定一个含有n个点的无项图,和m条边,问把这n个点连接起来最后最多剩下多少个孤立点,最少剩下多少个孤立点。

大致思路:我们知道,要想把n个点全部连接起来最多需要n (n + 1) / 2条边,所以我们可以逐个去掉n个点的每一个点,再在剩下的点里面按最多的边连边,最后看剩下多少个点。然后我们在来考虑剩下最少的点,要想保证最后剩下的点最少,我们就要使每个边尽可能多的连点,也就是说让一条边只连接两个点,每个点只有一条边相连,所以我们让m条边都连上点,最后在和0取最大值。

talk is cheap ,show me the code! .

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
	ll n,m;
	while(~scanf("%lld %lld",&n,&m)){
		ll minn,maxx;
		minn = n;
		maxx = -1;
		for(ll i = 0; i <= n; i++){
			ll k = n - i;
			k = k * (k - 1) / 2;
			if(k >= m) maxx = max(i,maxx);
		}
		while(m){
			m--;
			minn -= 2;
		}
		printf("%lld %lld\n",max(minn,0*1LL),maxx);
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值