Codeforces Round #457 (Div. 2) C. Jamie and Interesting Graph

Codeforces Round #457 (Div. 2)  C. Jamie and Interesting Graph


C. Jamie and Interesting Graph
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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


 题意 : 给你顶点数和边数,构造一个无向完全图,要求最小生成树与顶点 1 与 顶点  n 的最短路都是素数。


思路:   emmmmmm ,大概就是瞎搞几下吧!  要求是素数,所以开始打了个素数表,考虑至少有 n-1 边, 就先把 n- 1 条边构造 出来,并且把这个做成最小生成树,然后如果还有多的边就继续构造,把权值定为一个比较大的数就行。

注意素数表稍微打的大一点!!!



代码:

#include
using namespace std;

int n,m;
typedef pair pa;
bool vis[1900010];
map ma;
void init()
{
    memset(vis,0,sizeof vis);
    vis[1]=1;
    vis[0]=0;
    for(int i=2;i<=1900000;i++)
    {
        for(int j=i+i;j<=1900000;j+=i)
            vis[j]=1;
    }
}
int main()
{
    init();
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int flag=n-1;
        int  t=1;
        while(vis[flag+t])
        {
            t++;
           //cout<<"Ivis "<

你可能感兴趣的:(codeforse)