zoukankan      html  css  js  c++  java
  • CodeForces-916C-Jamie and Interesting Graph

    链接:

    https://vjudge.net/problem/CodeForces-916C

    题意:

    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!

    思路:

    构造,由1连其他点,权为2,在选1-2补上一个值,为mst权值和减去其他权为2的边的值.
    多余的边补1e9即可.

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    const int MAXN = 1e5+10;
    pair<pair<int, int>, int > pa[MAXN];
    
    //2*(n-1)
    bool Solve(int x)
    {
        for (int i = 2;i*i <= x;i++)
            if (x%i == 0)
                return true;
        return false;
    }
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n, m;
        cin >> n >> m;
        if (n == 2)
        {
            cout << "2 2" << endl;
            cout << "1 2 2" << endl;
            return 0;
        }
        for (int i = 1;i <= n-1;i++)
            pa[i].first.first = 1, pa[i].first.second = i+1, pa[i].second = 2;
        int v = 2*(n-2)+1;
        while (Solve(v))
            v++;
        pa[1].second = v-2*(n-2);
        int cnt = n;
        for (int i = 2;i <= n;i++)
        {
            if (cnt > m)
                break;
            for (int j = i+1;j <= n;j++)
            {
                pa[cnt].first.first = i;
                pa[cnt].first.second = j;
                pa[cnt].second = 1e9;
                cnt++;
                if (cnt > m)
                    break;
            }
        }
        cout << 2 << ' ' << v << endl;
        for (int i = 1;i <= m;i++)
            cout << pa[i].first.first << ' ' << pa[i].first.second << ' ' << pa[i].second << endl;
    
    
        return 0;
    }
    
  • 相关阅读:
    apache的日志切割
    实现HTTPS--Apache+Openssl
    CentOS 6.x 编译安装LAMP
    apache的域名跳转
    模型生成过程中检测到一个或多个验证错误
    电商时代已经要过去了。接下来是零售
    电商时代已经要过去了。接下来是零售
    华为手机怎么安装Google
    华为手机怎么安装Google
    table不让td中文字溢出操作方法
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11392395.html
Copyright © 2011-2022 走看看