Codeforces 916C - Jamie and Interesting Graph

Posted Wisdom+.+

tags:

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

916C - Jamie and Interesting Graph

思路:构造。

对于1到n最短路且素数,那么1到n之间连2

对于最小生成树,找一个稍微大点的素数(比1e5大)构造一个和为这个素数的最小生成树

剩下的边都连1e9

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))

/*const int N=1e5+5;
const int M=1e7+7;
vector<int>vc;
bool not_prime[M];
void prime(){
    for(int i=2;i<M;i++){
        if(!not_prime[i])vc.pb(i);
        for(int j=0;i*vc[j]<M;j++){
            not_prime[i*vc[j]]=true;
            if(i%vc[j]==0)break;
        }
    }
    cout<<vc[vc.size()-1]<<endl;//9999991
}*/
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //prime();
    int n,m,t=9999991;
    cin>>n>>m;
    if(n==2)cout<<2<< <<2<<endl;
    else cout<<2<< <<t<<endl;
    cout<<1<< <<n<< <<2<<endl;
    t-=2;
    for(int i=2;i<n;i++){
        if(i!=n-1)cout<<1<< <<i<< <<2<<endl,t-=2;
        else cout<<1<< <<i<< <<t<<endl;
    }
    m-=n-1;
    for(int i=2;i<=n;i++){
        if(m==0)break;
        for(int j=i+1;j<=n;j++){
            if(m==0)break;
            cout<<i<< <<j<< <<1000000000<<endl;
            m--;
            if(m==0)break;
        }
        if(m==0)break;
    }
    return 0;
}

 

以上是关于Codeforces 916C - Jamie and Interesting Graph的主要内容,如果未能解决你的问题,请参考以下文章

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

Jamie and Binary Sequence (changed after round) - CodeForces 916B

CodeForces-916B-Jamie and Binary Sequence(changed after round)(构造)

Codeforces 916B - Jamie and Binary Sequence (changed after round)

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

POJ2289 Jamie's Contact Groups(二分图多重匹配)