codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1581B.md (1523B)


      1 Source: https://codeforces.com/problemset/problem/1581/B
      2 
      3 B. Diameter of Graph
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 CQXYM wants to create a connected undirected graph with $n$ nodes and $m$ 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).
     22 
     23 The diameter of a graph is the maximum distance between any two nodes.
     24 
     25 The distance between two nodes is the minimum number of the edges on the path which endpoints are the two nodes.
     26 
     27 CQXYM wonders whether it is possible to create such a graph.
     28 
     29 Input
     30 
     31 The input consists of multiple test cases.
     32 
     33 The first line contains an integer $t (1 \leq t \leq 10^5)$ — the number of test cases. The description of the test cases follows.
     34 
     35 Only one line of each test case contains three integers $n(1 \leq n \leq 10^9)$, $m$, $k$ $(0 \leq m,k \leq 10^9)$.
     36 
     37 Output
     38 
     39 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).
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 5
     47 1 0 3
     48 4 5 3
     49 4 6 3
     50 5 4 1
     51 2 1 1
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 YES
     58 NO
     59 YES
     60 NO
     61 NO
     62 ```
     63 
     64 Note
     65 
     66 In the first test case, the graph's diameter equal to 0.
     67 
     68 In the second test case, the graph's diameter can only be 2.
     69 
     70 In the third test case, the graph's diameter can only be 1.