Codeforces Round #745 (Div. 2)B. Diameter of Graph

题目链接:Problem - 1581B - Codeforces

CQXYM wants to create a connected undirected graph with nn nodes and mm edges, and the diameter of the graph must be strictly less than k−1. Also, CQXYM doesn't want a graph that contains self-loops or multiple edges (i.e. each edge connects two different vertices and between each pair of vertices there is at most one edge).

The diameter of a graph is the maximum distance between any two nodes.

The distance between two nodes is the minimum number of the edges on the path which endpoints are the two nodes.

CQXYM wonders whether it is possible to create such a graph.

Input

The input consists of multiple test cases.

The first line contains an integer t(1≤t≤105) — the number of test cases. The description of the test cases follows.

Only one line of each test case contains three integers n(1≤n≤109), m, k(0≤m,k≤109).

Output

For each test case, print YES if it is possible to create the graph, or print NO if it is impossible. You can print each letter in any case (upper or lower).

Example

input

Copy

5
1 0 3
4 5 3
4 6 3
5 4 1
2 1 1

output

Copy

YES
NO
YES
NO
NO

Note

In the first test case, the graph's diameter equal to 0.

In the second test case, the graph's diameter can only be 2.

In the third test case, the graph's diameter can only be 1.

题意:问能不构造出一张图n个点, m条无向边,直径为恒小于k-1(任意两点的距离)

思路:如果k < 2,那么直径小于等于0,永远构造不出来

当k == 2的时候只有n==1, m==0可以构造出来解释如下:

构造图的边数是大于等于n - 1,小于等于 n * (n - 1) / 2的,(不能有重边,自环,而且所有点必须连在一起,负责就不满足)

当k == 3的时候m 必须等于n * (n - 1) / 2,否则就不可以

当k 大于3的时候m必须大于等于n-1,小于等于n * (n - 1) / 2;

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


int main(){
	int t;
	long long n, m, k;
	cin >> t;
	while(t--){
		cin >> n >> m >> k;
		if(k == 0 || k == 1){
			cout << "NO" << endl;
			continue;
		}
		if(k <= 2){
			if(n == 1){
				if(m > n * (n - 1) / 2){
					cout << "NO" << endl;
				}else{
					cout << "YES" << endl;
				}	
			}else{
				cout << "NO" << endl;
			}
		}else{
			if(k == 3){
				if(m == n * (n - 1) / 2){
					cout << "YES" << endl;
				}else{
					cout << "NO" << endl; 
				}
			}else{
				if(m >= n - 1 && m <= n * (n - 1) / 2){
					cout << "YES" << endl;
				}else{
					cout << "NO" << endl;
				}
			}
		}
		
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值