codeforces-scrape

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

916C.md (2754B)


      1 Source: https://codeforces.com/problemset/problem/916/C
      2 
      3 C. Jamie and Interesting Graph
      4 
      5 time limit per test
      6 
      7 2 seconds
      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 Jamie has recently found undirected weighted graphs with the following properties very interesting:
     22 
     23 * The graph is connected and contains exactly *n* vertices and *m* edges.
     24 * All edge weights are integers and are in range [1, 109] inclusive.
     25 * The length of shortest path from 1 to *n* is a prime number.
     26 * The sum of edges' weights in the minimum spanning tree (MST) of the graph is a prime number.
     27 * The graph contains no loops or multi-edges.
     28 
     29 If you are not familiar with some terms from the statement you can find definitions of them in notes section.
     30 
     31 Help Jamie construct any graph with given number of vertices and edges that is interesting!
     32 
     33 Input
     34 
     35 First line of input contains 2 integers *n*, *m* ![](https://espresso.codeforces.com/6ca64056ded326853311ef7f3c6fcb5dff8e5b40.png) — the required number of vertices and edges.
     36 
     37 Output
     38 
     39 In the first line output 2 integers *sp*, *mstw* (1 ≤ *sp*, *mstw* ≤ 1014) — the length of the shortest path and the sum of edges' weights in the minimum spanning tree.
     40 
     41 In the next *m* lines output the edges of the graph. In each line output 3 integers *u*, *v*, *w* (1 ≤ *u*, *v* ≤ *n*, 1 ≤ *w* ≤ 109) describing the edge connecting *u* and *v* and having weight *w*.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 4 4
     49 ```
     50 
     51 Output
     52 
     53 ```
     54 7 7  
     55 1 2 3  
     56 2 3 2  
     57 3 4 2  
     58 2 4 4
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 5 4
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 7 13  
     71 1 2 2  
     72 1 3 4  
     73 1 4 3  
     74 4 5 4
     75 ```
     76 
     77 Note
     78 
     79 The graph of sample 1: ![](https://espresso.codeforces.com/42f9750de41b0d9a6b21e8615170113cfe19b0f2.png) Shortest path sequence: {1, 2, 3, 4}. MST edges are marked with an asterisk (*).
     80 
     81 Definition of terms used in the problem statement:
     82 
     83 A shortest path in an undirected graph is a sequence of vertices (*v*1, *v*2, ... , *v**k*) such that *v**i* is adjacent to *v**i* + 1 1 ≤ *i* < *k* and the sum of weight ![](https://espresso.codeforces.com/e7f62cfd5c2c3b81dc80aaf2f512898495354f03.png) is minimized where *w*(*i*, *j*) is the edge weight between *i* and *j*. (<https://en.wikipedia.org/wiki/Shortest_path_problem>)
     84 
     85 A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. (<https://en.wikipedia.org/wiki/Prime_number>)
     86 
     87 A minimum spanning tree (MST) is a subset of the edges of a connected, edge-weighted undirected graph that connects all the vertices together, without any cycles and with the minimum possible total edge weight. (<https://en.wikipedia.org/wiki/Minimum_spanning_tree>)
     88 
     89 <https://en.wikipedia.org/wiki/Multiple_edges>