916C. Jamie and Interesting Graph(构图+思维)

Jamie has recently found undirected weighted graphs with the following properties very interesting:

  • The graph is connected and contains exactly n vertices and m edges.
  • All edge weights are integers and are in range [1, 109] inclusive.
  • The length of shortest path from 1 to n is a prime number.
  • The sum of edges' weights in the minimum spanning tree (MST) of the graph is a prime number.
  • The graph contains no loops or multi-edges.

If you are not familiar with some terms from the statement you can find definitions of them in notes section.

Help Jamie construct any graph with given number of vertices and edges that is interesting!

Input

First line of input contains 2 integers n, m  — the required number of vertices and edges.

Output

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.

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.

Examples
Input
4 4
Output
7 7
1 2 3
2 3 2
3 4 2
2 4 4
Input
5 4
Output
7 13
1 2 2
1 3 4
1 4 3
4 5 4
Note

The graph of sample 1: Shortest path sequence: {1, 2, 3, 4}. MST edges are marked with an asterisk (*).

题意:构造出一张n个点m条边的有向图,并且不存在环和重边,1到n的最短路为质数,最小生成树也为质数

思路:构造的最小生成树是一条链,也是一条最小路径,找到小于n-1的最大素数num,前n-2条边为1,最后一条

 为num-n+2; 其余边设为最大,不影响最小路径的性质即可;

#include
using namespace std;
const int N = 3e5+9;
int prime[N],tot;
void getPrime(){
	int vis[N]={0};
	vis[0]=vis[1]=1;
	for(int i=2;i


你可能感兴趣的:(贪心算法,找规律,Codeforces)