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

Posted Visitor

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #457 (Div. 2) CJamie and Interesting Graph相关的知识,希望对你有一定的参考价值。

【链接】 我是链接,点我呀:)
【题意】


在这里输入题意

【题解】


找比n-1大的最小的素数x
1-2,2-3..(n-2)-(n-1)长度都为1
然后(n-1)-n长度为(x-(n-2))
然后其他边长度都设为x+1就好了。
这样就能满足题意了。

【代码】

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

int n,m,ma;

bool is(int x){
    if (x<2) return false;
    int len = sqrt(x);
    for (int i = 2;i <= len;i++){
        if (x%i==0)
            return false;
    }
    return true;
}

int main(){
    #ifdef LOCAL_DEFINE
        freopen("rush_in.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    for (int i = n-1;;i++)
        if (is(i)){
            ma = i;
            break;
        }
    cout <<ma<<' '<<ma<<endl;
    for (int i = 1;i <= n-2;i++){
        cout <<i<<' '<<i+1<<" 1"<<endl;
    }
    cout <<n-1<<" "<<n<<" "<<ma-(n-2)<<endl;
    int now = n-1;
    for (int i = 1;i <= n &&now<m;i++)
        for (int j = i+1;j <= n && now <m;j++){
            if (j != (i+1)){
                cout <<i<<" "<<j<<" "<<ma+1<<endl;
                now++;
            }
        }
    return 0;
}

以上是关于Codeforces Round #457 (Div. 2) CJamie and Interesting Graph的主要内容,如果未能解决你的问题,请参考以下文章

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

Codeforces Round #457 (Div. 2) A Jamie and Alarm Snooze

Codeforces Round #457 (Div. 2) BJamie and Binary Sequence

Codeforces Round #457 (Div. 2) D. Jamie and To-do List 主席树

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)