1. 程式人生 > >【Codeforces Round #457 (Div. 2) C】Jamie and Interesting Graph

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

include pac bits namespace mark span .com ifd 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) C】Jamie and Interesting Graph